asdf: Pip doesn't get the correct version when virtualenv is activated

System:

asdf 0.2.1 Python plugin installed with 2.7.10 and 3.6.0 versions

Steps to reproduce:

$ asdf global 2.7.10
$ mkdir version3
$ cd version3
$ asdf local python 3.6.0
$ pip -V

Outputs the correct version pip 9.0.1 from /Users/<username>/.asdf/installs/python/3.6.0/lib/python3.6/site-packages (python 3.6)

$ virtualenv new
$ . new/bin/activate
$ pip -V

Outputs the WRONG version pip 9.0.1 from /Users/<username>/version3/new/lib/python2.7/site-packages (python 2.7)

Conclusion

I don’t know if I’m doing something wrong, but I expected pip to get the version of the current local config.

If its by virtualenv’s design, please add a command asdf which python to get the path of the current python so we can pass to virtualenv’s -p flag.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

If using Python3, I usually do

python -m venv myvenv

I never had any issue with this.

For python -m virtualenv myenv to work, you need to have the virtualenv pip package installed. AFAIK, this is indeed the only way to get it to work for Python 2. For Python >= 3.3, the module venv is part of the standard library so python -m venv myenv will work out of the box. But -m virtualenv would of course also work provided that the virtualenv package is installed.

@tuvistavie I think the addition of a which command would be a good idea. That would give us three related commands:

  • current - print the current version and the path to the tool-version file
  • where - show the path to the root of a specific version
  • which - show the path to the current version of the specified executable

Thanks @fcrespo82 for the workaround. Another even shorter option we eventually found (just adding here for future references) is: $(asdf where python)/bin/virtualenv myvenv It will use the correct python version just as well.

For workaround I am doing

virtualenv -p $(asdf where python $(asdf current python))/bin/python myenv

python -m venv venv would indeed create a virtual environment in the venv directory relative to the current directory. Unless using whatever shell hook, you would need to activate it using source venv/bin/activate or so though.