1

I am trying to make a python 2.7 environment but when I run

$ mkvirtualenv --python=python2.7 venv
$ python

Python 3.6.5 (default, Jun 17 2018, 12:13:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

I get a python3.6 install. Any idea what is up here?

Here is output with absolute path and verbose flags

 Jeff$ mkvirtualenv -v --python=/usr/bin/python2.7 neovim2
Running virtualenv with interpreter /usr/bin/python2.7
Creating /Users/Jeff/.virtualenvs/neovim2/lib/python2.7
Symlinking Python bootstrap modules
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/lib-dynload
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/config
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/os.py
  Ignoring built-in bootstrap module: posix
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/posixpath.py
  Cannot import bootstrap module: nt
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/ntpath.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/genericpath.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/fnmatch.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/locale.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/encodings
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/codecs.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/stat.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/UserDict.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/copy_reg.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/types.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/re.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/sre.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/sre_parse.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/sre_constants.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/sre_compile.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/warnings.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/linecache.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/_abcoll.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/abc.py
  Symlinking /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/_weakrefset.py
Creating /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/site-packages
Writing /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/site.py
Writing /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/orig-prefix.txt
Writing /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/no-global-site-packages.txt
Creating parent directories for /Users/Jeff/.virtualenvs/neovim2/include
Symlinking /Users/Jeff/.virtualenvs/neovim2/include/python2.7
Creating /Users/Jeff/.virtualenvs/neovim2/bin
New python executable in /Users/Jeff/.virtualenvs/neovim2/bin/python
Changed mode of /Users/Jeff/.virtualenvs/neovim2/bin/python to 0755
Symlinking /Users/Jeff/.virtualenvs/neovim2/.Python
Testing executable with /Users/Jeff/.virtualenvs/neovim2/bin/python -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))"
Got sys.prefix result: u'/Users/Jeff/.virtualenvs/neovim2'
Creating /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/distutils
Writing /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/distutils/__init__.py
Writing /Users/Jeff/.virtualenvs/neovim2/lib/python2.7/distutils/distutils.cfg
Installing setuptools, pip, wheel...
  Looking in links: /usr/local/lib/python3.6/site-packages, /usr/local/lib/python3.6/site-packages/virtualenv_support
  Collecting setuptools
    Using cached https://files.pythonhosted.org/packages/7f/e1/820d941153923aac1d49d7fc37e17b6e73bfbd2904959fffbad77900cf92/setuptools-39.2.0-py2.py3-none-any.whl
  Collecting pip
  Collecting wheel
  Installing collected packages: setuptools, pip, wheel
  Successfully installed pip-10.0.1 setuptools-39.2.0 wheel-0.31.1
...Installing setuptools, pip, wheel...done.
Writing /Users/Jeff/.virtualenvs/neovim2/bin/activate
Writing /Users/Jeff/.virtualenvs/neovim2/bin/activate.fish
Writing /Users/Jeff/.virtualenvs/neovim2/bin/activate_this.py
Writing /Users/Jeff/.virtualenvs/neovim2/bin/activate.csh
Writing /Users/Jeff/.virtualenvs/neovim2/bin/python-config
Changed mode of /Users/Jeff/.virtualenvs/neovim2/bin/python-config to 0755
virtualenvwrapper.user_scripts creating /Users/Jeff/.virtualenvs/neovim2/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/Jeff/.virtualenvs/neovim2/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/Jeff/.virtualenvs/neovim2/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/Jeff/.virtualenvs/neovim2/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/Jeff/.virtualenvs/neovim2/bin/get_env_details
 neovim2  Jeff $ python
Python 3.6.5 (default, Jun 17 2018, 12:13:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
0

3 Answers 3

3

Your path variable is picking up another python..

Try

which python and

path

to help you execute the right python

Sign up to request clarification or add additional context in comments.

1 Comment

I have tried it with an absolute path as well and it still doesn't work. $ python brings up python 3 and python2.7 or /usr/bin/python2.7 brings up python 2. Shouldn't this mean my paths are correct?
3

--python does not use PATH variable. Either default Python (the one /usr/bin/python points to) will be used, or you have to specify full path to executable. But with your invocation you should get "The executable xxx (from --python=xxx) does not exist", like:

$ mkvirtualenv --python=python3 test
The executable /home/jazg/python3 (from --python=/home/jazg/python3) does not exist

But:

$ mkvirtualenv --python=/usr/bin/python3 test
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/jazg/v/test/bin/python3
Also creating executable in /home/jazg/v/test/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
$ python --version
Python 3.5.2

5 Comments

I tried using the absolute path and it still didnt work
And no error message, just silently your python spec from --python was ignored? Unbelievable. What's the output when run with -v? Does it work if you use plain virtualenv (without wrapper)?
I posted the verbose output and yes it appears to fail silently with no error and give me the wrong version of python (check my edited question)
It does not "fail" - apparrently venv is created but somehow wrong python is later used. Activate this venv manually (by source <path_to_venv>/bin/activate, not workon) and check PATH variable, its bin dir should be 1st item. If not - you have bigger problem in your system.
If you had used which python (as I had recommended), the alias would have been immediately apparent btw.
-1

You didn't do a source venv/bin/activate after creating the venv. Try that ;)

2 Comments

mkvirtualenv does that automatically
Then why your interpreter doesn't show the activated environment?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.