简体   繁体   English

如何在 Jupyter Notebook 中使用我的 PyCharm Python 解释器?

[英]How to use my PyCharm Python Interpreter in Jupyter Notebook?

Is it possible to use the Python interpreter that I have been using in PyCharm in Jupyter Notebook?是否可以在 Jupyter Notebook 中使用我在 PyCharm 中使用的 Python 解释器? I'm not looking to create a brand new virtual environment as I have tried that and encountered "Solving Environment" issues when trying to install packages.我不打算创建一个全新的虚拟环境,因为我已经尝试过并且在尝试安装软件包时遇到了“解决环境”问题。 How do I get Jupyter Notebook to use my current interpreter ~/opt/anaconda3/envs/PopulationDensity/bin/python as the interpreter?如何让 Jupyter Notebook 使用我当前的解释器~/opt/anaconda3/envs/PopulationDensity/bin/python作为解释器?

I have also tried python -m ipykernel install --user --name <kernel_name> --display-name "<Name_to_display>" as suggested in another thread and substituted <kernel_name> with my interpreter path, but that resulted in a syntax error.我还按照另一个线程中的建议尝试python -m ipykernel install --user --name <kernel_name> --display-name "<Name_to_display>"并将<kernel_name>替换为我的解释器路径,但这导致了语法错误.

The simplest solution is to install Jupyter notebook in the interpreter that Pycharm happens to use and invoke Jupyter notebook from there.最简单的解决方案是在 Pycharm 碰巧使用的解释器中安装 Jupyter notebook,然后从那里调用 Jupyter notebook。

As Pycharm creates new virtual environments for your projects(by default settings), you need to first activate that interpreter.当 Pycharm 为您的项目创建新的虚拟环境时(默认设置),您需要首先激活该解释器。

The Jupyter notebook invoked like above has access to all packages that Pycharm has access to.像上面那样调用的 Jupyter notebook 可以访问 Pycharm 可以访问的所有包。

Open up a terminal, active the venv and then:打开一个终端,激活 venv 然后:

pip install notebook
jupyter notebook

In every running Python you can check the interpreter path with:在每个正在运行的 Python 中,您可以使用以下命令检查解释器路径:

import sys
print(sys.executable)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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