使用 Atom 中的氢设置 Python 虚拟环境 [英] Setting Up a Python Virtual Environment with Hydrogen in Atom

查看:41
本文介绍了使用 Atom 中的氢设置 Python 虚拟环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 VS Code 切换到 Atom,我正在尝试为我的 Python 项目设置一个虚拟环境.

I'm in the middle of switching from VS Code to Atom and I'm trying to set up a virtual environment for my python project.

在 VS Code 中很容易做到,我会运行以下脚本,当我运行脚本时,它会自动开始使用新的 env(带有所有必需的包):

It was pretty easy to do in VS Code, I'd run the following script and it would automagically start using the new env (with all the required packages) when I'd run the script:

python3 -m venv my_env
source my_env/bin/activate
pip3 install -r requirements.txt

现在我正在尝试将 Hydrogen 设置为以相同的方式工作.当我运行与 Hydrogen 内联的代码行时,我希望它们在具有从 requirements.txt 文件中导入我需要的模块的虚拟环境中运行.

Now I'm trying to set up Hydrogen to work the same way. When I run lines of code inline with Hydrogen, I want them to be run in a virtual environment that has the imported modules I need from a requirements.txt file.

我能够使用以下命令安装 python3 内核:

I was able to install the python3 kernel with the following commands:

python3 -m venv my_environment_name      # create a virtual environment
source my_environment_name/bin/activate  # activate the virtual environment
python -m pip install ipykernel          # install the python kernel (ipykernel) into the virtual environment
python -m ipykernel install   

Atom 能够看到它:截图

And Atom is able to see it: Screenshot

然而,我仍然对如何将我的依赖项安装到内核中感到困惑.如果我确实在那里安装了我的依赖项,我不希望我的下一个 python 项目在那里安装所有这些模块.我很想拥有虚拟环境所承诺的新鲜石板.

However, I'm still puzzled as how to install my dependencies into the kernel. And if I do install my dependencies there, I don't want my next python projects to have all those modules in there. I'd love to have the fresh-slate that virtual environments promise.

这里的任何帮助将不胜感激.有没有人有搭建一个可以被Hydrogen包使用的虚拟环境的经验?

Any help here would be appreciated. Has anyone had expereince setting up a virual environment that can be used by the Hydrogen package?

推荐答案

好的,经过一些更多的实验,我能够连接到我已经安装了我的 requirements.txt 的内核.

Ok, after some more experimentation, I was able to connect to a kernel that I had installed my requirements.txt into.

以下是我采取的步骤:

python3 -m venv env
source env/bin/activate
# make sure requirements.txt has ipykernel in it
pip3 install -r requirements.txt 
python -m ipykernel install --user --name=env

然后在 Atom 中,按 cmd-shift-p 并找到 Hydrogen: Update Kernels.

Then in Atom, press cmd-shift-p and find Hydrogen: Update Kernels.

之后,我可以通过再次执行 cmd-shift-p 并选择 Hydrogen: Start Local Kernel 并选择 env 来使用内核>.

After, I was able to use the kernel by doing cmd-shift-p again and selecting Hydrogen: Start Local Kernel and selecting env.

当我通过 Hydrogen 运行 import 语句时(选择它们并按 cmd-enter),他们现在知道要导入什么了!天啊!

When I would run import statements via Hydrogen (selecting them and pressing cmd-enter), they would now know what to import! Horray!

这篇关于使用 Atom 中的氢设置 Python 虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆