I have spent enough amount of time on this setup and thought this would be helpful to many?. Here’s how you can setup your PyCharm to work in a charming manner with Virtualenvs.
This will be a short post until I get some more time to explain the brief.
How do I make PyCharm work with VirtualEnv setup?
Couple of things you should change for the PyCharm to work with the Virtualenvs:
Prepare a virtualenvs folder
I’ll add this content later. Basically, set up your virtualenvs into a directory of your choosing and do it properly.
Prepare a bashrc file – for generic use of virtualEnv
nano or vi a file named “.bashrc” in the user home directory: ~/ with the following content:
export WORKON_HOME=~/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 export PATH="/usr/local/sbin:$PATH" #Java Compat for Apache Spark #export JAVA_HOME=$(/usr/libexec/java_home) #One more line for Apache Spark, default python to be used. #export PYSPARK_PYTHON=python3 #Anotherline for Apache Spark, default python to be used. #export PYSPARK_DRIVER_PYTHON=python3 #For the Apache Spark #export SPARK_HOME="/usr/local/Cellar/apache-spark/1.6.2/libexec/" source /usr/local/bin/virtualenvwrapper.sh
Note: here “~/.virtualenvs” is where my virtualenvs are located and “pyenv” is my default virtualenv and that is the one I’m going to be using below.
Create pycharmrc file – for PyCharm’s charm
nano or vi a file named “.pycharmrc” in the user home directory ~/ with the following content:
source ~/.bashrc workon pyenv
This file basically replicates what you should do manually if you want the above virtualenv to be triggered in a normal shell/terminal window.
Change preferences settings for PyCharm
There are two major things to be changed over here:
Change the default terminal initialization to use our rc file
Add virtualenv into PyCharm interpreters
Add our virtualenv into the interpreter list for your PyCharm to understand that we’re using a virtualenv:
As an additional note, ensure that you’ve the following setting set up as well:
I hope this was brief and useful!