Passing Python3 to virtualenvwrapper throws up ImportError
Asked Answered
S

3

7

I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!

$ 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.
Sextodecimo answered 30/9, 2015 at 8:57 Comment(6)
This appears to be a bug, see e.g. github.com/PythonCharmers/python-future/issues/148 (pro-tip: search for your error messages).Uncinate
Thanks for the comment @Uncinate Much appreciated. That didn't come up in my search which prompted me to post it here. So, I guess I'll have to use pyvenv for now.Sextodecimo
Have you found a solution?Edi
No, I haven't found it yet @EliKorvigoSextodecimo
@EliKorvigo I've just submitted an answer. Please check if it helps you.Sextodecimo
@Sextodecimo I've already found the same solution, if we can call it that way. Anyway, +1. I guess some folks might find it useful.Edi
S
2

This is sort of a workaround for now.

Create a virtualenv using pyvenv.

# install pyvenv on Ubuntu
sudo apt-get install python3-venv

To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,

pyvenv example ~/.virtualenvs/example

This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper

Hope this helps.

Sextodecimo answered 9/10, 2015 at 12:42 Comment(1)
pyvenv ~/.virtualenvs/example is enough. Then workon example works.Tung
A
5

I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.

Adne answered 12/10, 2015 at 6:40 Comment(1)
Another bleeding edge alternative is: pip install --upgrade https://github.com/pypa/virtualenv/archive/develop.zip, please see github.com/pypa/virtualenv/issues/812 as reference.Holub
S
2

This is sort of a workaround for now.

Create a virtualenv using pyvenv.

# install pyvenv on Ubuntu
sudo apt-get install python3-venv

To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,

pyvenv example ~/.virtualenvs/example

This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper

Hope this helps.

Sextodecimo answered 9/10, 2015 at 12:42 Comment(1)
pyvenv ~/.virtualenvs/example is enough. Then workon example works.Tung
A
1

You can upgrade to the most recent version of virtualenv, with:

sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it

The following command then works:

mkvirtualenv scriptcutter --python=/usr/bin/python3

Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of @pjotr_dolphin's comment, with the URL updated.

Anthropomorphic answered 17/7, 2017 at 13:46 Comment(1)
This one worked for me on Dec 2017, but I didn't have to use the url.Mandatory

© 2022 - 2024 — McMap. All rights reserved.