在PYTHONPATH中应该设置什么?

时间:2021-10-05 23:13:12

I'm going through and writing a setup doc for other developers at work for a python project and I've been reading up on the PYTHONPATH environment variable. I'm looking at my current development system and think I have a few things set wrong that is causing my IDE (IntelliJ) to behave incorrectly when looking up the python libraries.

我正在为一个python项目的其他开发人员编写一个setup doc,我正在阅读PYTHONPATH环境变量。我正在查看当前的开发系统,并认为我设置了一些错误的东西,这导致我的IDE (IntelliJ)在查找python库时行为不正确。

I've looked at the documentation here and here and I'm still unsure of what should actually be in the PYTHONPATH environment variable.

我已经在这里和这里查看了文档,我仍然不确定在PYTHONPATH环境变量中应该有什么。

I have PYTHONHOME pointed to `C:\Python27'.

我把PYTHONHOME指向了C:\Python27’。

My current PYTHONPATH is set to PYTHONHOME. Should I also add the directories from sys.path?

我当前的python路径被设置为PYTHONHOME。我还应该从sys.path中添加目录吗?

UPDATE:

更新:

Based on the below information, PYTHONPATH does not need to be set unless there are non-standard libraries that you want python to be able to find by default. For instance, when I install wxPython from the installer it will add its libraries to PYTHONPATH. I do set PYTHONHOME to the root of the python installation so that I can add it to my system PATH environment variable so that I can run python from any where.

基于以下信息,无需设置PYTHONPATH,除非有您希望python能够在默认情况下找到的非标准库。例如,当我从安装程序安装wxPython时,它会将库添加到PYTHONPATH中。我确实将PYTHONHOME设置为python安装的根,这样我就可以将它添加到我的system PATH环境变量中,这样我就可以在任何地方运行python。

2 个解决方案

#1


30  

You don't have to set either of them. PYTHONPATH can be set to point to additional directories with private libraries in them. If PYTHONHOME is not set, Python defaults to using the directory where python.exe was found, so that dir should be in PATH.

你不需要设置它们中的任何一个。可以设置PYTHONPATH指向附加目录,其中包含私有库。如果没有设置PYTHONHOME, Python默认使用Python所在的目录。已经找到exe,所以应该在PATH中。

#2


19  

For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find its standard library.

对于大多数安装,您不应该设置这些变量,因为Python不需要它们来运行。Python知道在哪里找到它的标准库。

The only reason to set PYTHONPATH is to maintain directories of custom Python libraries that you do not want to install in the global default location (i.e., the site-packages directory).

设置PYTHONPATH的唯一原因是维护自定义Python库的目录,您不希望将这些目录安装在全局默认位置(例如。网站目录)。

Make sure to read: http://docs.python.org/using/cmdline.html#environment-variables

请务必阅读:http://docs.python.org/using/cmdline.html#environment-variables

#1


30  

You don't have to set either of them. PYTHONPATH can be set to point to additional directories with private libraries in them. If PYTHONHOME is not set, Python defaults to using the directory where python.exe was found, so that dir should be in PATH.

你不需要设置它们中的任何一个。可以设置PYTHONPATH指向附加目录,其中包含私有库。如果没有设置PYTHONHOME, Python默认使用Python所在的目录。已经找到exe,所以应该在PATH中。

#2


19  

For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find its standard library.

对于大多数安装,您不应该设置这些变量,因为Python不需要它们来运行。Python知道在哪里找到它的标准库。

The only reason to set PYTHONPATH is to maintain directories of custom Python libraries that you do not want to install in the global default location (i.e., the site-packages directory).

设置PYTHONPATH的唯一原因是维护自定义Python库的目录,您不希望将这些目录安装在全局默认位置(例如。网站目录)。

Make sure to read: http://docs.python.org/using/cmdline.html#environment-variables

请务必阅读:http://docs.python.org/using/cmdline.html#environment-variables