Forums

Problem creating Python 3 virtualenvs

Hi everyone, someone wrote in complaining that they couldn't make a Python3.3 virtualenv. Traceback looks like this:

$ mkvirtualenv -p python3.3 p3
Running virtualenv with interpreter /usr/local/bin/python3.3
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 2560, in <module>
    main()
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 874, in main
    default_search_dirs = file_search_dirs()
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 601, in file_search_dirs
    import virtualenv
  File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1525, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1023, in load_module
  File "<frozen importlib._bootstrap>", line 1004, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 854, in _load_module
  File "<frozen importlib._bootstrap>", line 990, in get_code
  File "<frozen importlib._bootstrap>", line 1051, in _cache_bytecode
  File "<frozen importlib._bootstrap>", line 1065, in set_data
OSError: [Errno 30] Read-only file system: '/usr/local/lib/python2.7/site-packages/__pycache__'

We're not quite sure why it's happening yet, but there is a pleasingly recursive workaround: create a normal python2 virtualenv first, reinstall virtualenv into it, and then create your python3 virtualenv from inside it:

mkvirtualenv xzibit
pip install virtualenv
mkvirtualenv -p python3.3 my_python3_virtualenv

Looks related to this bug. It was fixed and patched last year though, and we downloaded + compiled our python3.3 this month! hmmm...

Ah. looks like the fix isn't in 3.3.0, which is what we install. We'll have to wait for 3.3.1 I guess. In the meantime, the workaround looks fine...

It's actually a funny work around though...☺

I was quite pleased with it :)

No doubt!!

It's virtualenv all the way down!

Stephen Hawking would be so pleased to hear...☺