![](/img/trans.png)
[英]/usr/bin/python3: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper')
[英]Passing Python3 to virtualenvwrapper throws up ImportError
我正在嘗試使用virtualenvwrapper
來制作基於python 3的virtualenv
。 但是,當我傳遞可選的解釋器參數時,我看到了這個錯誤。 我正在運行Ubuntu 15.04。 我嘗試重新安裝virtualenv
和virtualenvwrapper
但沒有成功。 感謝你的幫助!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
我遇到了同樣的問題,但在我將virtualenv降級到12.0.2之后,這個問題就消失了。
現在這是一種解決方法。
使用pyvenv
創建virtualenv
。
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
為了最大限度地減少正常工作流程中的中斷,請傳遞與virtualenvwrapper
使用的目標目錄相同的目標目錄。
pyvenv example ~/.virtualenvs/example
這將自動與workon
和cdproject
命令一起使用。 我沒有使用virtualenvwrapper
提供的其他東西
希望這可以幫助。
您可以使用以下命令升級到virtualenv的最新版本:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
然后,以下命令有效:
mkvirtualenv scriptcutter --python=/usr/bin/python3
顯然,開發分支已被刪除,因此帶有“develop”的URL將不再起作用。 我的回答是基於@ pjotr_dolphin的評論,並更新了URL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.