簡體   English   中英

安裝了virtualenv,但仍然出現“ ModuleNotFoundError:沒有名為“ virtualenv”的模塊”錯誤

[英]Installed virtualenv, but still getting “ModuleNotFoundError: No module named 'virtualenv'” error

我正在使用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?

您可以只刪除virtualenv rm -r ./your_venv ,然后創建一個新的python3 -m virtualenv your_venv並激活此source ./your_venv/bin/activate 現在您處於分離的環境中。 例如,在這種狀態下,您可以安裝libs pip install -r ./requirements.txt 這些庫將僅安裝在您的環境內部,而不是全局安裝。

嘗試python -m virtualenv myenv -m標志表示模塊。 使用此命令,您明確地告訴python將腳本virtualenv作為腳本運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM