Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activating Python Virtual Environment in Atom

Don't have much expertise in programming. Only picked up Python last summer.

I have installed both Atom and Conda on my computer. Recently, I've used Atom to edit my scripts in Python, then run the scripts via Command Line. As per standard practice, I created Virtual Environments where I installed packages I needed to run different Python scripts.

I now want to use Atom as an IDE, and so have installed the Script package on Atom so I can run my scripts in Atom itself. However, when I tried running a Python script that required the Python numpy package, I got this:

ImportError: No module named 'numpy'

This error is obviously going to appear for other packages that haven't already been installed in the root environment (I think?).

So now, my question is how do I activate the needed Virtual Environment in Atom? In other applications like Jupyter and Spyder, I would activate the Virtual Environment I needed then open the Application via Command Line, but I can't do that with Atom.

(If possible, is there a way to use Virtual Environments created by Conda)

Thanks

like image 262
m_cheah Avatar asked Jan 20 '17 20:01

m_cheah


People also ask

How do I activate the Virtualenv in an Atom?

Now in the Atom software, at the bottom left of the screen, press noVirtualenv. A window opens where your Virtualenv name is displayed, and you can select it by tapping on it. Now your Virtualenv is ready and you can create or import your own project and get started. Save this answer.


2 Answers

One way is to start atom from the activated virtual environment. In this case, executing programs/scripts uses the configured python interpreter and imports the installed in the virtual environment.

EDIT: It's been long though, it might be useful for people redirected to this question.

By installing atom-python-virtualenv you can create, change or deactivate virtual environments with atom editor.

like image 121
Bussller Avatar answered Sep 18 '22 13:09

Bussller


The hydrogen package for Atom works well for this.

You will also need to install Jupyter into your conda environment and Hydrogen should pick up the IPython kernel automatically.

like image 28
leej3 Avatar answered Sep 16 '22 13:09

leej3