How to specify python3 kernel in jupyter in pyChar

2019-04-30 08:27发布

问题:

Here is my setting and this is my script

I am trying to use jupyter notebook in pyCharm, but it kept using python2 instead of python3.

Any idea about this problem?

Add:

this pic is running jupyter notebook in chrome.

回答1:

The preferences image you show is indeed how you would setup your interpreter for PyCharm, but that's not what the output/logging of PyCharm looks like. I'm guessing that's a jupyter-notebook display, which means you are running into the issue in jupyter-notebook and not PyCharm. So you need to change your setup for jupyter. Based on some quick searching pip install jupyter will install a python 2.7 version of jupyter. Sounds like what you want is

pip3 install jupyter

which will install the python3 version for you. You will likely have to uninstall your current version of jupyter.



回答2:

When you kick off Jupyter-notebook from within PyCharm there is a configuration which is created. If the configuration is initially 2.7 ( I think it defaults to the current interpreter), and then keep using that same configuration, it wouldn't matter the state of the current project interpreter because it would be using the value saved in the run configuration.

You can modify your run configuration by

  1. Run | Run...

  1. Edit Configurations...

  1. Select your Jupyter Notebook run configuration on the left (here is untitled4)

  2. Make sure the python interpreter is correct here on the right

I was able to start a jupyter notebook like this and get it to output python 3 by doing this. Hope this is what you are needing.



回答3:

My problem was that I had multiple kernels, and PyCharm launches the default kernel. One approach might be to configure PyCharm to specify the kernel of choice to start up, I didn't investigate how to do that. I simply changed the default kernel in Jupyter and this worked for me (I have a virtualenv for tensorflow). c.MultiKernelManager.default_kernel_name = 'tensorflow'.