Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Up a Python Virtual Environment with Hydrogen in Atom

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 experience setting up a virtual environment that can be used by the Hydrogen package?

like image 647
Tim Estes Avatar asked Jun 04 '20 19:06

Tim Estes


People also ask

How to set up a Python environment in atom?

Setting Up a Python Environment in Atom Step 1: Checking Your Python Version. To get the most out of Atom your co m puter needs to be running Python 3. To check... Step 2: Download Atom. Go to Atom’s Website and click on download. Step 3: Packages. Now that you have Atom on your computer it’s time ...

What is hydrogen in Python?

Python, Julia and R with Atom + Hydrogen One of the main reasons to use Atom is the Hydrogen package , which is an interactive coding environment that supports Python, R and Julia kernels. Put simply, Hydrogen lets you run code inline and in real time, which is the ideal workflow for rapid developing.

How do I use hydrogen with Anaconda Python?

Once we have Anaconda Python installed (or any Python distribution + Jupyter), we can now install Hydrogen itself. In Atom, go to Settings (Ctrl+Comma) and in the Install pane look for hydrogen and install it. Now we’re ready for interactive coding! Create a new file with a.py (or.R or.jl) extension and write some code.

Can atom be used as a python IDE?

Setting up Atom as a Python IDE [A How To Guide] The guide shows how you can setup and maintain a python friendly development environment from within Atom. In a separate article I (will) show how to setup Microsoft Visual Studio Code in a similar manner. The guide is tested and valid for the latest version of Atom 1.40-40-Python 3.


1 Answers

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 
python3 -m ipykernel install --user --name=env

Then in Atom, press cmd-shift-p and find Hydrogen: Update Kernels.
Or manually Packages->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!

like image 165
Tim Estes Avatar answered Sep 19 '22 17:09

Tim Estes