Virtualenv: Virtualenv 20.0.0b1 error creating venv for brew python2

Created on 28 Jan 2020  ·  10Comments  ·  Source: pypa/virtualenv

On my Mac with Homebrew Python2 (and 3):

$ ls -al $(which python2)
lrwxr-xr-x  1 brettmz  admin  37 Nov 15 12:04 /usr/local/bin/python2 -> ../Cellar/python@2/2.7.17/bin/python2

I get:

$ virtualenv --python /usr/local/bin/python2 py2env
Traceback (most recent call last):
  File "/Users/brettmz/Library/Python/3.7/bin/virtualenv", line 8, in <module>
    sys.exit(run())
  File "/Users/brettmz/Library/Python/3.7/lib/python/site-packages/virtualenv/__main__.py", line 16, in run
    run_via_cli(args)
  File "/Users/brettmz/Library/Python/3.7/lib/python/site-packages/virtualenv/run/__init__.py", line 21, in run_via_cli
    session = session_via_cli(args)
  File "/Users/brettmz/Library/Python/3.7/lib/python/site-packages/virtualenv/run/__init__.py", line 33, in session_via_cli
    raise RuntimeError("failed to find interpreter for {}".format(discover))
RuntimeError: failed to find interpreter for Builtin discover of python_spec='/usr/local/bin/python2'

This works without error for current stable virtualenv. Is this intended?

Most helpful comment

With the unmodified beta, this works:

virtualenv --python=/usr/local/bin/python2.7 foo

Either works with your current discovery branch.

Thanks for your quick reply.

All 10 comments

@matthew-brett I'll need to validate, thanks for bringing this to my attention.

Hmmm, I cannot reproduce this 🤔 can you post the output with -vvv?

Sure:

89 setup logging to NOTSET [DEBUG report:43]
161 find interpreter for spec PythonSpec(str_spec=/usr/local/bin/python2, path=/usr/local/bin/python2) [INFO builtin:44]
161 proposed PythonInfo(spec=CPython3.7.5.final.0-64, exe=/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7, platform=darwin, version='3.7.5 (v3.7.5:5c02a39a0b, Oct 14 2019, 19:07:34) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]', encoding_fs_io=utf-8-UTF-8) [INFO builtin:48]
162 Attempting to acquire lock 4568075728 on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/480187601bdac08cce463831e50aade5e1a71f4acabcd8828b0a0dd3276fab64.lock [DEBUG filelock:270]
162 Lock 4568075728 acquired on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/480187601bdac08cce463831e50aade5e1a71f4acabcd8828b0a0dd3276fab64.lock [INFO filelock:274]
163 get PythonInfo from /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/480187601bdac08cce463831e50aade5e1a71f4acabcd8828b0a0dd3276fab64.json for /usr/local/bin/python2 [DEBUG cached_py_info:67]
163 Attempting to release lock 4568075728 on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/480187601bdac08cce463831e50aade5e1a71f4acabcd8828b0a0dd3276fab64.lock [DEBUG filelock:315]
163 Lock 4568075728 released on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/480187601bdac08cce463831e50aade5e1a71f4acabcd8828b0a0dd3276fab64.lock [INFO filelock:318]
163 proposed PythonInfo(spec=CPython2.7.17.final.0-64, exe=/usr/local/bin/python2.7, original=/usr/local/opt/python@2/bin/python2.7, platform=darwin, version='2.7.17 (default, Oct 24 2019, 12:57:38) \n[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.8)]', encoding_fs_io=utf-8-None) [INFO builtin:48]
164 discover PATH[0]=/usr/local/opt/ruby/bin [DEBUG builtin:75]
164 discover PATH[1]=/Library/Frameworks/Python.framework/Versions/3.7/bin [DEBUG builtin:75]
164 discover PATH[2]=/Users/brettmz/usr/local/fsl/bin [DEBUG builtin:75]
165 discover PATH[3]=/Users/brettmz/Library/Python/3.7/bin [DEBUG builtin:75]
165 Attempting to acquire lock 4564090384 on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d.lock [DEBUG filelock:270]
165 Lock 4564090384 acquired on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d.lock [INFO filelock:274]
166 get PythonInfo from /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d.json for /Users/brettmz/Library/Python/3.7/bin/python [DEBUG cached_py_info:67]
166 Attempting to release lock 4564090384 on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d.lock [DEBUG filelock:315]
166 Lock 4564090384 released on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d.lock [INFO filelock:318]
166 proposed PythonInfo(spec=CPython3.7.5.final.0-64, exe=/Users/brettmz/Library/Python/3.7/bin/python, platform=darwin, version='3.7.5 (v3.7.5:5c02a39a0b, Oct 14 2019, 19:07:34) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]', encoding_fs_io=utf-8-UTF-8) [INFO builtin:48]
167 discover PATH[4]=/usr/sbin [DEBUG builtin:75]
167 discover PATH[5]=/sbin [DEBUG builtin:75]
167 discover PATH[6]=/Users/brettmz/usr/bin [DEBUG builtin:75]
167 discover PATH[7]=/usr/local/bin [DEBUG builtin:75]
168 discover PATH[8]=/usr/bin [DEBUG builtin:75]
168 Attempting to acquire lock 4564099344 on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/aaafe28a6254581d4f0ccfa0911e2de9e463b78fe3b32b118542e908e534a6ec.lock [DEBUG filelock:270]
168 Lock 4564099344 acquired on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/aaafe28a6254581d4f0ccfa0911e2de9e463b78fe3b32b118542e908e534a6ec.lock [INFO filelock:274]
168 get PythonInfo from /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/aaafe28a6254581d4f0ccfa0911e2de9e463b78fe3b32b118542e908e534a6ec.json for /usr/bin/python [DEBUG cached_py_info:67]
169 Attempting to release lock 4564099344 on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/aaafe28a6254581d4f0ccfa0911e2de9e463b78fe3b32b118542e908e534a6ec.lock [DEBUG filelock:315]
169 Lock 4564099344 released on /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/aaafe28a6254581d4f0ccfa0911e2de9e463b78fe3b32b118542e908e534a6ec.lock [INFO filelock:318]
169 proposed PythonInfo(spec=CPython2.7.16.final.0-64, exe=/usr/bin/python, original=/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python, platform=darwin, version='2.7.16 (default, Nov  9 2019, 05:55:08) \n[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s', encoding_fs_io=utf-8-None) [INFO builtin:48]
169 discover PATH[9]=/bin [DEBUG builtin:75]
169 discover PATH[10]=/usr/sbin [DEBUG builtin:75]
169 discover PATH[11]=/sbin [DEBUG builtin:75]
170 discover PATH[12]=/Library/TeX/texbin [DEBUG builtin:75]
170 discover PATH[13]=/opt/X11/bin [DEBUG builtin:75]
170 done in 82ms [INFO __main__:23]
Traceback (most recent call last):
  File "/Users/brettmz/Library/Python/3.7/bin/virtualenv", line 8, in <module>
    sys.exit(run())
  File "/Users/brettmz/Library/Python/3.7/lib/python/site-packages/virtualenv/__main__.py", line 16, in run
    run_via_cli(args)
  File "/Users/brettmz/Library/Python/3.7/lib/python/site-packages/virtualenv/run/__init__.py", line 21, in run_via_cli
    session = session_via_cli(args)
  File "/Users/brettmz/Library/Python/3.7/lib/python/site-packages/virtualenv/run/__init__.py", line 33, in session_via_cli
    raise RuntimeError("failed to find interpreter for {}".format(discover))
RuntimeError: failed to find interpreter for Builtin discover of python_spec='/usr/local/bin/python2'

This part seems the relevant information:
```
161 find interpreter for spec PythonSpec(str_spec=/usr/local/bin/python2, path=/usr/local/bin/python2) [INFO builtin:44]

163 get PythonInfo from /Users/brettmz/Library/Application Support/virtualenv/py-info/20.0.0b1/480187601bdac08cce463831e50aade5e1a71f4acabcd8828b0a0dd3276fab64.json for /usr/local/bin/python2 [DEBUG cached_py_info:67]

163 proposed PythonInfo(spec=CPython2.7.17.final.0-64, exe=/usr/local/bin/python2.7, original=/usr/local/opt/python@2/bin/python2.7, platform=darwin, version='2.7.17 (default, Oct 24 2019, 12:57:38) \n[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.8)]', encoding_fs_io=utf-8-None) [INFO builtin:48]
````

Seems somehow /usr/local/bin/python2 translates to /usr/local/bin/python2.7... What does /usr/local/bin/python2.7 point too?

It gives:

$ ls -al /usr/local/bin/python2.7
lrwxr-xr-x  1 brettmz  admin  39 Nov 15 12:04 /usr/local/bin/python2.7 -> ../Cellar/python@2/2.7.17/bin/python2.7

Starting the interpreter directly with /usr/local/bin/python2 works OK, but I guess that follows from the fact it works from older virtualenv.

$ /usr/local/bin/python2
Python 2.7.17 (default, Oct 24 2019, 12:57:38) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

I think https://github.com/pypa/virtualenv/pull/1513 will fix this if you can give it a try 🤔

To be fair the correct test here would be to try to create a python first with /usr/local/bin/python2.7 and then /usr/local/bin/python2... and both should work.

I believe https://github.com/pypa/virtualenv/pull/1513 fixed this, at least according to my tests, if not please feel free to report back and we'll reopen the issue.

With the unmodified beta, this works:

virtualenv --python=/usr/local/bin/python2.7 foo

Either works with your current discovery branch.

Thanks for your quick reply.

Thanks for taking the time to test-drive the new version

thanks

Was this page helpful?
0 / 5 - 0 ratings