atom编辑设置python编程环境_在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.

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

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.

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

And Atom is able to see it:

Screenshot

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.

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

解决方案

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

Here are the steps I took:

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

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

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值