在 windows 上的自定义目录中安装 python 模块

install python module in custom directory on windows

我想在我公司的 windows 机器上安装 pip,但我没有管理员权限,所以我必须在其他地方安装它。

当我在前缀中设置路径时:

python setup.py install --prefix="C:\Developers\lib"

出现错误:

running install
Checking .pth file support in C:\Developers\pythonLib\Lib\site-packages\
C:\Program Files (x86)\Python27\pythonw.exe -E -c pass
TEST FAILED: C:\Developers\pythonLib\Lib\site-packages\ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
    C:\Developers\lib\Lib\site-packages\
and your PYTHONPATH environment variable currently contains:

''

Here are some of your options for correcting the problem:

* You can choose a different installation directory, i.e., one that is
  on PYTHONPATH or supports .pth files

* You can add the installation directory to the PYTHONPATH environment
  variable.  (It must then also be on PYTHONPATH whenever you run
  Python and want to use the package(s) you are installing.)

* You can set up the installation directory to support ".pth" files by
  using one of the approaches described here:

  https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations

Please make the appropriate changes for your system and try again.

你有什么建议吗?谢谢!

更新:

我没有编辑环境变量的权限,所以我以为我不能编辑Pythonpath。但我注意到我可以使用

set PYTHONPATH=C:\Developers\pythonLib\Lib\site-packages

,然后是

python setup.py install --prefix="C:Developers\pythonLib"

解决问题。

将您的目录添加到 PYTHONPATH 环境变量,然后您就可以使用 python setup.py install --prefix=dirpip install package_name -t dir.

在那里安装软件包

但我建议改用 virtualenv

将 python 软件包安装到特定文件夹的最简单方法是使用 -t, --target <dir> 命令。这会将软件包安装到 <dir>。默认情况下,这不会替换 <dir>.

中现有的 files/folders

命令:pip 安装--target <path directory> <package name>

例如:pip install --target C:\test requests