gpt4 book ai didi

Python interpteter 无法在 virtualenv 中找到模块,但 pip 看到它并且不会安装

转载 作者:太空狗 更新时间:2023-10-30 01:37:30 25 4
gpt4 key购买 nike

我正在尝试在 Nervana 为他们的 Neon 深度学习包创建的 virtualenv 中使用 pytools 模块,但似乎无法找到 pytools 或 pip 它。当我进入我的 virtualenv 时,我看到了这个行为:

me@ARL--M6800:~/Downloads/neon$ source .venv/bin/activate
(.venv) me@ARL--M6800:~/Downloads/neon$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import pytools
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pytools
>>>

>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.7/dist-packages', '/home/me/Downloads/neon',
'/home/me/Downloads/neon/.venv/lib/python2.7',
'/home/me/Downloads/neon/.venv/lib/python2.7/plat-x86_64-linux-gnu',
'/home/me/Downloads/neon/.venv/lib/python2.7/lib-tk',
'/home/me/Downloads/neon/.venv/lib/python2.7/lib-old',
'/home/me/Downloads/neon/.venv/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/me/Downloads/neon/.venv/local/lib/python2.7/site-packages',
'/home/me/Downloads/neon/.venv/lib/python2.7/site-packages']



(.venv) me@ARL--M6800:~/Downloads/neon$ pip install pytools
Requirement already satisfied (use --upgrade to upgrade): pytools in
/usr/local/lib/python2.7/dist-packages/pytools-2016.1-py2.7.egg
Requirement already satisfied (use --upgrade to upgrade):
decorator>=3.2.0 in /usr/local/lib/python2.7/dist-packages (from pytools)
Requirement already satisfied (use --upgrade to upgrade): appdirs>=1.4.0
in /usr/local/lib/python2.7/dist-packages/appdirs-1.4.0-py2.7.egg (from
pytools)
Requirement already satisfied (use --upgrade to upgrade): six>=1.8.0 in
/usr/local/lib/python2.7/dist-packages (from pytools)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6.0 in
/usr/local/lib/python2.7/dist-packages (from pytools)

因此,我无法导入 pytools,因为它不在我的 sys.path 中。根据pip,安装在/usr/local/lib/python2.7/dist-packages/pytools-2016.1-py2.7.egg目录下,留给我 3 个问题:

首先:为什么我的 virtualenv 可以看到我的系统范围的包?我以为默认是看不到它们。当我查看用于创建 virtualenv 的 Makefile 时,我看到了这个

  # where our installed python packages will live
VIRTUALENV_DIR := .venv
VIRTUALENV_EXE := virtualenv -p python2.7 # use pyvenv for python3 install
ACTIVATE := $(VIRTUALENV_DIR)/bin/activate

这应该给我默认行为。

其次:为什么我的 dist-packages 目录中有 egg 目录?这不会让找到这些模块变得更难吗? (虽然显然,我的系统环境 python 的 sys.path 已更新为在 egg 目录中搜索。何时/如何???)

第三:什么是修复问题的有效方法,以便我的 virtualenv 可以访问 pytools?

(我会为我的列表编号而不是第一/第二/第三,但是我插入的 Makefile 代码格式不正确)

最佳答案

首先,我对Nervana's Neon一无所知。

当使用 root 权限创建 virtualenv 时,我得到相同的 sys.path:

dm@Z580:~$ sudo virtualenv test1 -p python2.7
[sudo] password for dm:
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in test1/bin/python2.7
Also creating executable in test1/bin/python
Installing setuptools, pip, wheel...done.
dm@Z580:~$ source test1/bin/activate
(test1)dm@Z580:~$ which python
/home/dm/test1/bin/python
(test1)dm@Z580:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import pprint
>>> pprint.pprint(sys.path)
['',
'/home/dm/test1/lib/python2.7',
'/home/dm/test1/lib/python2.7/plat-x86_64-linux-gnu',
'/home/dm/test1/lib/python2.7/lib-tk',
'/home/dm/test1/lib/python2.7/lib-old',
'/home/dm/test1/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/dm/test1/local/lib/python2.7/site-packages',
'/home/dm/test1/lib/python2.7/site-packages']

我会删除当前的 virtualenv,在没有 sudo 的情况下重新创建它,然后使用 virtualenv 的 pip 安装所有要求。

cd ~/Downloads
rm -rf neon/.venv/
virtualenv neon/.venv/ -p python2.7
source neon/.venv/bin/activate
pip install -r neon/requirements.txt

关于Python interpteter 无法在 virtualenv 中找到模块,但 pip 看到它并且不会安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36749736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com