简体   繁体   中英

How do I properly use virtualenv with Anaconda?

I am on OSX and I have two virtual environments setup for Python 2.7 and 3.x

These were installed using homebrew following this guide , which seems to setup my bash environment correctly.

I am encountering a brick wall with the anaconda user configuration though. Here is my user configuration:

{
    "python_interpreter": "$VIRTUAL_ENV/bin/python",
    "display_signatures": true,
    "pep8_max_line_length": 120,
}

This is my bash output for $VIRTUAL_ENV. I am running sublime from my bash terminal.

$ echo $VIRTUAL_ENV
/Users/rpg711/.virtualenvs/python3

This is my sublime console output for a test build using the anaconda build environment:

/bin/bash: /bin/python: No such file or directory

Here it seems to be looking for /bin/python, as if $VIRTUAL_ENV is evaluating to an empty string.

And the final sanity check... everything seems to be fine here:

(python3) $ python --version
Python 3.6.1
(python3) $ which python
/Users/rpg711/.virtualenvs/python3/bin/python

Anyone know what is going on here? I might be doing something wrong.

Sublime project settings override the user config weirdness. This is the only way to be sure that each project is being developed with the correct virtual environment interpreter. Still launching sublime from a shell with the virtual environment activated.

I used

"settings": {
        "python_interpreter": "~/.virtualenvs/[envname]/bin/python"
}

As long as the .sublime-project file exists, no issues with anaconda interpreter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM