pycharm on osx with venv, path incomplete

Pycharm running on osx (mac catalina) configured to work in venv. The command

os.system("which python") shows /usr/local/bin/python instead of /user/..../venv/bin/python

I was able to solve this issue by adding  the /venv/bin path to the pycharm configuration, used to execute the py file that has the line os.system("which python").

On windows, that isn't needed.

On mac, my project interpreter sees that its configured for a virtualenv...it says "Python3.7 virtualenv at ~/....

So I just wanted to bring this strange difference between windows & mac to your attention. Perhaps I'm doing something wrong....

Thanks.....I'm very happy with Pycharm and actively use it on Linux, Mac & Windows.

 

0
4 comments

Hi, taking your Mac OS configuration into consideration:

1. What is returned by `sys.executable` running from PyCharm?

2. What is the output of `which python` from the terminal with activated virtualenv? 

Normally you should not add any paths manually to your environment for it to work.

0

thanks for your consideration.

 

sys.executable returns:

/Users/bronlib/development/trialproject/venv_mac/bin/python

 

(when called with the default configuration; no manual intervention)

which python

/usr/local/bin/python

 

0

> I was able to solve this issue by adding  the /venv/bin path

 

This path should already be in your PATH env variable in activated virtualenv

 

>(when called with the default configuration; no manual intervention)

>which python

>/usr/local/bin/python

 

This means the virtual environment is not activated properly in the terminal. I don't think the issue is IDE-related though.

Does the issue reproduce if you activate virtualenv in the terminal (outside of IDE) and do `which python` from there?

0

I didn't activate the virtual environment on purpose: I have different project each with their own virtual environment. I like to work with each of them without having to relaunch pycharm.  I realise that that is not how the majority of the people work.  So, indeed, if I would just launch "which python" on my command line I would see /local/bin/python and not the virtual environment. 

 

 

0

Please sign in to leave a comment.