This is a beginner python
installation question. This the first time I have tried to install and call a package. I've got pip
installed, and I tried to install two modules - numpy
and pandas
.
In terminal, I ran the following commands:
sudo pip install numpy
sudo pip install pandas
Both commands returned with a success message. Here is the pandas
success message (it's the second package I installed and was still in my terminal history):
Successfully installed pandas
Cleaning up...
pip
returned a similar message after numpy
was installed.
Now, when I launch python
and try to call it with:
import pandas
I get this error message:
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named pandas
Same when I try numpy
.
Can anyone tell me what I'm doing incorrectly?
Locally installed Python and all packages will be installed under a directory similar to ~/. local/bin/ for a Unix-based system, or \Users\Username\AppData\Local\Programs\ for Windows.
To check all the installed Python modules, we can use the following two commands with the 'pip': Using 'pip freeze' command. Using 'pip list command.
By default, on Linux, Pip installs packages to /usr/local/lib/python2.
argh. you've got two pythons in your path that are the same version? don't do that.
pip, easy-install, etc are associated with a particular python install and will use that python by default. so if you have a system-provided python and a system-provided easy_install (or installed easy_install yourself using the system python) then easy_install will, by default, install packages for the system python.
the best way to avoid this mess, imho, is to use use system python for that version (2.7 probably) and, for other versions, use make alt-install
when installing, which will give you executables like python3.1
and the like. if you really need to replace the version provided by the system, uninstall it.
once you've done that. each python will have a distinct name (ending in the version) and python
will remain the system one.
next, when you install easy_install, you'll notice that there are version-specific versions (easy_install-2.7
for example). use those. if one is missing, then install distutils with the appropriate python (eg use python3.1
and you'll get an easy_install-3.1
). unfortunately, each time you do this (iirc) you overwrite the un-versioned easy_install
, so never use that - always use the versioned one.
alternatively, you could not install easy_install or pip for anything other than the system version, then always use virtualenv. virtualenv will let you specify a python version (so you can use the system virtualenv for all pythons installed) and then installs easy_install/pip for the python you use. so once you're inside the virtual environment, everything just works.
and i just realised i haven't much experience with pip, so i can't actually help with that (except to note that virtualenv does provide it) (about which is preferable: it used to be that pip was better maintained; i think these days the latest distutils/easy_install is as good as pip, but pip has a few more features that i have never used).
disclaimer: the above is from experience gained developing lepl, which runs on 2.6 to 3.2, so i need to test it on all those. as far as i know, what i describe above works for me, but i have no deep knowledge of python/easy_install/pip so i may have some mistakes in rationalising/describing things (in other words, i'm writing all this in case it helps, but i'm a bit worried i have an error - please, someone correct me if so).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With