繁体   English   中英

virtualenv 使用了错误的 pip 文件夹

[英]virtualenv uses wrong pip folder

我有一个新的 macbook,然后我需要重新配置我的工具。 Python 3 通过 brew 安装,virtualenv 和 virtualwrapper 与 pip 一起安装。 当我创建一个新环境时,我可以使用 pip 安装包,但 python 看不到它们。 Python 只能使用安装在 virtualenv 之外的包。 有什么办法解决吗?

mbp:f4mily-1st sebastienmorele$ mkvirtualenv test
Using base prefix '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/sebastienmorele/.virtualenvs/test/bin/python3.7
Also creating executable in /Users/sebastienmorele/.virtualenvs/test/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/sebastienmorele/.virtualenvs/test/bin/get_env_details
(test) mbp:f4mily-1st sebastienmorele$ pip install selenium
Collecting selenium
  Using cached https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl
Collecting urllib3 (from selenium)
  Using cached https://files.pythonhosted.org/packages/e6/60/247f23a7121ae632d62811ba7f273d0e58972d75e58a94d329d51550a47d/urllib3-1.25.3-py2.py3-none-any.whl
Installing collected packages: urllib3, selenium
Successfully installed selenium-3.141.0 urllib3-1.25.3
(test) mbp:f4mily-1st sebastienmorele$ python
Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'selenium'
>>> 
(test) mbp:f4mily-1st sebastienmorele$ 
(test) mbp:f4mily-1st sebastienmorele$ deactivate 
mbp:f4mily-1st sebastienmorele$ pip list
Package           Version
----------------- -------
pbr               5.4.3  
pip               19.2.3 
setuptools        41.0.1 
six               1.12.0 
stevedore         1.31.0 
urllib3           1.25.3 
virtualenv        16.7.5 
virtualenv-clone  0.5.3  
virtualenvwrapper 4.8.4  
wheel             0.33.4 
mbp:f4mily-1st sebastienmorele$ pip install selenium
Collecting selenium
  Using cached https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl
Requirement already satisfied: urllib3 in /usr/local/lib/python3.7/site-packages (from selenium) (1.25.3)
Installing collected packages: selenium
Successfully installed selenium-3.141.0
mbp:f4mily-1st sebastienmorele$ workon test
(test) mbp:f4mily-1st sebastienmorele$ python
Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
>>> 

如果您尝试访问安装在其外部的virtualenv中的软件包,那么这会破坏虚拟环境的全部意义。

一个独立的目录树,其中包含特定版本的 Python 的 Python 安装,以及许多附加包。

更多信息在这里

不用担心,这很容易理解,点击它。

其次,如果您已经在您的虚拟环境中并且仍然无法找到您已经安装的那些软件包,请查看您是如何安装它们的。

如果您使用pip install *package* ,则软件包已安装在 python2.* 环境中。

鉴于您使用的是 python3.*,请尝试pip3 install *package*命令,然后检查包。

谢谢你的回答。 我知道如何使用 virtualenv。 使用 pip3 不能解决我的问题:

(test) [~/projets/adsence_autovisit]$ pip3 install requests
Collecting requests
  Using cached https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl
Requirement already satisfied: certifi>=2017.4.17 in /Users/sebastienmorele/.virtualenvs/test/lib/python3.7/site-packages (from requests) (2019.9.11)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Users/sebastienmorele/.virtualenvs/test/lib/python3.7/site-packages (from requests) (1.25.5)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Users/sebastienmorele/.virtualenvs/test/lib/python3.7/site-packages (from requests) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in /Users/sebastienmorele/.virtualenvs/test/lib/python3.7/site-packages (from requests) (2.8)
Installing collected packages: requests
Successfully installed requests-2.22.0
(test) [~/projets/adsence_autovisit]$ python
Python 3.7.4 (default, Sep  7 2019, 18:27:02) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
>>> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM