【问题标题】:virtualenv uses wrong pip foldervirtualenv 使用了错误的 pip 文件夹
【发布时间】:2019-09-20 07:22:24
【问题描述】:

我有一个新的 macbook,然后我需要重新配置我的工具。通过 brew 安装的 Python 3、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
>>> 

【问题讨论】:

    标签: python virtualenv virtualenvwrapper


    【解决方案1】:

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

    包含 Python 安装的自包含目录树 对于特定版本的 Python,加上一些额外的 包。

    更多信息here

    不用担心,很好理解,点一下吧。

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

    如果你使用pip install *package*,那么包已经安装在python2.*环境中了。

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

    【讨论】:

    【解决方案2】:

    感谢您的回答。我知道如何使用 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'
    >>> 
    

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 2017-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 2016-05-13
      • 2016-02-11
      • 1970-01-01
      相关资源
      最近更新 更多