问题
So i downloaded the lastfm api for python made by people. found here: http://code.google.com/p/python-lastfm/
I have a website hosting through dreamhost. I wasnt able to build the module using:
python setup.py build
in my shell that i used putty to get into. But when i would run
python setup.py install
it would return an error. Figuring that all install really does is throw the files from the lib dir into the python site-packages folder, i decided to try and manually do it. I was successful in doing so on my local machine and was able to run python and type import lastfm with no errors. But i could not get it working on my webhost.
I do have quite the clusterfuck currently on my webhost due to my n00bism, by that i mean i tried installing python multiple times, and i dont really know where it installed successfully. All i know is i can go to putty and type python and it will run, but i dont know exactly where from. So i copied the lastfm build over to every python2.x/lib/site-packages i could find, but to no avail.
I dont know what im doing wrong. It says pythons os path is usr/lib/python2.5 and i figure usr means the root or local. idk. im very confused.
I also am curious because i am able to import things like mysql and sqlite by typing
import MySQLdb
import sqlite
import sqlite3
and all those work, yet i dont see them anywhere in my python path.
thanks in advance. if i need to list more info please tell me. thanks!
edit:
$ python setup.py install running install error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the installation directory:
[Errno 13] Permission denied: '/usr/lib/python2.5/site-packages/test-easy-install-11740.write-test'
The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:
/usr/lib/python2.5/site-packages/
Perhaps your account does not have write access to this directory? If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable.
For information on other options, you may wish to consult the documentation at:
http://peak.telecommunity.com/EasyInstall.html
Please make the appropriate changes for your system and try again.
that is the error i would get when i would try to do python setup.py install
回答1:
Python packages are searched in your PYTHONPATH
. If you do echo $PYTHONPATH
or
import sys
print sys.path
you will get a list of directories from where the modules are being imported.
In your case with python-lastfm, you are installing using one version of Python and trying to run the program using another version. This is most often the case of confusion when you find that something is not getting imported. Use the full path of python /usr/bin/python2.6
or do a which python
and try to use full path to build and install using setup script and try again.
回答2:
In some Linux-Distributions (Debian, Ubuntu) site-packages
is not in PYTHONPATH
. You could add it to your PYTHONPATH
, place a link in dist-packages
or add a path configuration file.
Documentation: Modifying Python’s Search Path
回答3:
Most of the time, to install python packages on any UNIX
based system (linux/os x/bsd) you need to do:
sudo python setup.py install
This is, of course, if you have sudo rights.
来源:https://stackoverflow.com/questions/5114536/python-not-importing