Using Pip When Running Both Python 2.7 and Python 3

I’m currently running Python 2.7 and Python 3 alongside each other on a Windows 10 machine. That made managing modules a bit challenging.

Normally, when I would want to install a new module, I’d use Pip. Specifically, I’d open a Windows Command Line, and type in:

pip install <name of the module>

With two versions of Python on the same machine, though, Pip seems to get confused. It doesn’t know which version of Python it should use when installing modules.

In my case, Pip was installing modules for Python 2.7 instead of Python 3. Even when I ran Pip3 instead of Pip, the same issue persisted. I would install a module using Pip3, and when I went to run it, I’d get the error “ModuleNotFoundError: No module named <name of module>”

The Solution

What ended up working was running pip from within Python.

In Python 3, Pip finally comes packaged with Python itself. That means you can run it as a module, instead of needing to run it as an external program.

In my case, I ran:

python3 -m pip install <name of the module>

That worked to install the module for Python 3.

Weirdly, my modules end up in a really bizarre location on my computer. They worked fine when running Python from the command line, but within Aptana, importing packages still failed.

I fixed that my adding to full (bizarre) path to my site-packages folder to my PYTHONPATH:


Now, modules run well in Python 3!

Leave a Reply