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

时间:2015-06-29 18:19:53

标签: python python-2.7 pip

我正在尝试在我公司的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"

解决问题。

2 个答案:

答案 0 :(得分:0)

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

但我建议改用virtualenv

答案 1 :(得分:0)

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

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

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