Setting Up a Python Virtual Environment with Hydrogen in Atom

孤街醉人 提交于 2020-08-05 17:26:57

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/62202986/setting-up-a-python-virtual-environment-with-hydrogen-in-atom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!