简体   繁体   中英

How do I set PYTHONPATH / Installing Selenium

I am trying to run a small program from the command line under Linux. The program runs correctly when I use IDLE but I cant run it from the command line. I ran this little program to tell me my path:

import sys
print sys.path

Under IDLE I have the following entry:

/usr/local/lib/python2.7/dist-packages 
/usr/lib/python2.7/dist-packages

These entries are not there when I run under the command line. The package that I need to import (selenium) is in dist-packages. I get the following error when trying to import selenium.

from selenium import webdriver
...
ImportError: No module named selenium

I have tried pip install selenium, pip uninstall selenium, doesnt fix the problem. When I try python setup.py install (on the selenium install file) I get:

error: invalid command 'easy_install'

How can I solve this problem - do I have to add: /usr/local/lib/python2.7/dist-packages to my path, and if so how do I do that?

You can just do one of the following:

1.Add the path to sys.path

import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages')

2.Add to PYTHONPATH from commandline

export PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python2.7/dist-packages"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM