在命令行上提供临时 PYTHONPATH? [英] Provide temporary PYTHONPATH on the commandline?

查看:50
本文介绍了在命令行上提供临时 PYTHONPATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑类似的事情

python3 my_script.py --pythonpath/path/to/some/necessary/modules

有这样的吗?我知道(我认为)Pycharm 在您使用它执行脚本时会临时修改 PYTHONPATH;Pycharm 是怎么做的?

Is there something like this? I know (I think) that Pycharm temporarily modifies PYTHONPATH when you use it to execute scripts; how does Pycharm do it?

我想这样做的原因是我有一些代码通常需要在我自己的机器上运行(这很好,因为我使用 Pycharm 来运行它)但有时需要在远程服务器上运行(在命令行上)),并且它不起作用,因为远程服务器没有 Pycharm 自动临时添加的 PYTHONPATH .我不想 export PYTHONPATH=[...] 因为经常更改它很麻烦(假设它确实需要经常更改).

The reason I want to do this is that I have some code that usually needs to run on my own machine (which is fine because I use Pycharm to run it) but sometimes needs to run on a remote server (on the commandline), and it doesn't work because the remote server doesn't have the PYTHONPATHs that Pycharm automatically temporarily adds. I don't want to export PYTHONPATH=[...] because it's a big hassle to change it often (and suppose it really does need to change often).

推荐答案

您可以像这样在环境变量中指定 python 路径:

You can specify the python path in an environment variable like so:

PYTHONPATH=/path/to/some/necessary/modules python3 my_script.py

这篇关于在命令行上提供临时 PYTHONPATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆