我将系统更新至 Ubuntu 20.04
我已经在我的 Python 虚拟环境中Python 3.6.7
运行virtualenv
它了。virtualenvwrapper
更新后
我可以检查已创建的虚拟环境列表,但是当我尝试创建新的虚拟环境时mkvirtualenv -p python newenv
我收到此消息
Traceback (most recent call last):
File "/home/abcd/.local/bin/virtualenv", line 7, in <module>
from virtualenv import main
ImportError: cannot import name 'main' from 'virtualenv' (/usr/lib/python3/dist-packages/virtualenv/__init__.py)
然后我检查了更新后的python版本Python 3.8.5
我检查了main
里面virtualenv
Python 3.8.5
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from virtualenv import main
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'main' from 'virtualenv' (/usr/lib/python3/dist-packages/virtualenv/__init__.py)
>>>
我尝试安装virtualenv
并virtualwrapper
Python 3.8.5
python -m pip install virtualenv virtualenvwrapper
因为我的默认Python
版本是3.8.5
更新后
即使安装后我也收到同样的消息ImportError: cannot import name 'main' from 'virtualenv'
我找到了这个帖子在 Ubuntu 20.04 上创建 Python 3.6 虚拟环境的问题
按照建议安装Python 3.6.7
最受欢迎的答案
cd opt
sudo wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz
sudo tar -xvf Python-3.6.7.tgz
cd Python-3.6.7
make clean
sudo ./configure
sudo make
sudo make install
更新了我的bashrc
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/home/abcd/.local/bin/virtualenv
# Virtual Environment Wrapper
source /home/abcd/.local/bin/virtualenvwrapper.sh
对于 VIRTUALENVWRAPPER_PYTHON
which python3
/usr/local/bin/python3
对于 VIRTUALENVWRAPPER_VIRTUALENV
sudo find / -name "virtualenv"
/home/abcd/.local/bin/virtualenv
对于virtualenvwrapper.sh
sudo find / -name "virtualenvwrapper.sh"
/home/abcd/.local/bin/virtualenvwrapper.sh
source ~/.bashrc
Python3 -V
显示器Python 3.6.7
Python -V
显示器Python 3.8.5
安装virtualenv
并virtualenvwrapper
用于Python 3.6.7
Python3 -m pip install virtualenv virtualenvwrapper
现在我尝试使用创建虚拟环境Python 3.6.7
mkvirtualenv -p python3 newenv
我收到了同样的消息
Traceback (most recent call last):
File "/home/abcd/.local/bin/virtualenv", line 7, in <module>
from virtualenv import main
ImportError: cannot import name 'main' from 'virtualenv' (/usr/lib/python3/dist-packages/virtualenv/__init__.py)
当我进去Python 3.6.7
检查Python 3.8.5
from virtualenv import main
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from virtualenv import main
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'main' from 'virtualenv' (/usr/lib/python3/dist-packages/virtualenv/__init__.py)
>>>
Python 3.6.7 (default, May 26 2021, 09:24:09)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from virtualenv import main
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'main'
>>>
这里的解决方案是什么?