【问题标题】:Installed virtualenv, but still getting "ModuleNotFoundError: No module named 'virtualenv'" error安装了 virtualenv,但仍然收到“ModuleNotFoundError: No module named 'virtualenv'”错误
【发布时间】:2019-07-21 10:24:33
【问题描述】:

我正在使用 CentOS 7 并想运行“virtualenv”命令。所以我尝试卸载并重新安装它...

[myuser@server ~]$ sudo pip uninstall virtualenv
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Cannot uninstall 'virtualenv'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
[myuser@server ~]$ sudo pip install virtualenv
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: virtualenv in /usr/lib/python2.7/site-packages (15.1.0)

但是当我去实际运行它时,我被告知它没有安装。

[myuser@server ~]$ virtualenv myenv
Traceback (most recent call last):
  File "/usr/bin/virtualenv", line 2, in <module>
    import virtualenv
ModuleNotFoundError: No module named 'virtualenv'

WTF??

【问题讨论】:

    标签: python python-3.x pip centos virtualenv


    【解决方案1】:

    您可以删除 virtualenv rm -r ./your_venv,然后创建新的 python3 -m virtualenv your_venv 并激活此 source ./your_venv/bin/activate。现在您处于分离的环境中。例如,在这种状态下,您可以安装您的库 pip install -r ./requirements.txt。这些库将仅安装在您的环境中,而不是全局安装。

    【讨论】:

      【解决方案2】:

      试试python -m virtualenv myenv-m 标志表示模块。使用此命令,您明确告诉 python 将模块 virtualenv 作为脚本运行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-07-18
        • 2020-05-24
        • 1970-01-01
        • 2021-04-13
        • 1970-01-01
        • 1970-01-01
        • 2019-05-10
        相关资源
        最近更新 更多