PyCharm: How do I call frameworkpython so that it

2019-07-31 23:53发布

问题:

I'm using matplotlib library with my virtualenv. If you use it this way, matplotlib will not plot the graph because it is not the python framework, but the python as per the virtualenv. This problem has been documented on the matplotlib website: http://matplotlib.org/faq/virtualenv_faq.html

You will end up with this error if you try running it with just the virtualenv python:

Python is not installed as a framework

I decided to use their second workaround which is to include the function PYTHONHOME into my bashrc. file.

I have included the function below into bashrc taken off the matplotlib website:

function frameworkpython {
    if [[ ! -z "$VIRTUAL_ENV" ]]; then
        PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python "$@"
    else
        /usr/local/bin/python "$@"
    fi
}

Now, to run matplotlib successfully, I need to call frameworkpython instead of python to draw the graph. This is all good in my Terminal where I just type in the commands but I would rather use PyCharm to run my python code.

My question is, how do I get PyCharm to ran frameworkpython each time I press the green play button? The green play button just calls python.

I clicked on "Edit Configurations..." but cannot see how to change this. You can change the interpreters but frameworkpython is not an interpreter but rather a function within the bashrc file.

回答1:

You can set your Python interpreter in Pycharm. See: https://www.jetbrains.com/help/pycharm/2016.1/configuring-available-python-interpreters.html