Leo Leo - 1 year ago 492
Linux Question

linux-python suddenly cannot find modules

I am in real panic now. I was running my code just fine. Then I tried to install webdriver and then bam! I cannot run my python code anymore, it said it cannot find any modules that I have installed or basic modules. Please look at the command lines below. Help is really appreciated. I don't understand what happened or what I did wrong:

[ec2-user folder]$ sudo python new_html_crawl.py
2016-05-28 06:18:22.943352
Traceback (most recent call last):
File "new_html_crawl.py", line 134, in <module>
dict_data = de.crawl(url)
File "new_html_crawl.py", line 83, in crawl
result = self.get_content(link)
File "new_html_crawl.py", line 37, in get_content
driver = webdriver.Chrome('/usr/bin/google-chrome')
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 61, in __init__
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 69, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'google-chrome' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x7f8e0decc410>> ignored
[ec2-user folder]$ which chromedriver
/usr/bin/which: no chromedriver in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin)
[ec2-user folder]$ sudo which chromedriver
which: no chromedriver in (/sbin:/bin:/usr/sbin:/usr/bin)
[ec2-user folder]$ sudo mv chromedriver /usr/local/lib/python2.7/site-packages/ /usr/bin
mv: cannot stat ‘chromedriver’: No such file or directory
[ec2-user folder]$ cd /usr/bin
[ec2-user bin]$ sudo wget http://chromedriver.storage.googleapis.com/2.21/chromedriver_linux64.zip
--2016-05-28 06:24:19-- http://chromedriver.storage.googleapis.com/2.21/chromedriver_linux64.zip
Resolving chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)..., 2607:f8b0:400a:806::2010
Connecting to chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2692616 (2.6M) [application/zip]
Saving to: ‘chromedriver_linux64.zip’

chromedriver_linux6 100%[===================>] 2.57M --.-KB/s in 0.06s

2016-05-28 06:24:19 (43.1 MB/s) - ‘chromedriver_linux64.zip’ saved [2692616/2692616]

[ec2-user bin]$ sudo unzip chromedriver_linux64.zip
Archive: chromedriver_linux64.zip
inflating: chromedriver
[ec2-user bin]$ sudo which chromedriver
[ec2-user bin]$ sudo python new_html_crawl.py
python: can't open file 'new_html_crawl.py': [Errno 2] No such file or directory
[ec2-user usr]$ cd /home
[ec2-user home]$ cd ec2-user/
[ec2-user ~]$ cd folder/
[ec2-user folder]$ sudo python new_html_crawl.py
Traceback (most recent call last):
File "new_html_crawl.py", line 8, in <module>
import requests
ImportError: No module named requests

As you can see, at the first line, I was still able to run the code, but then at the end it said Import error. I highly suspect the mv command:

sudo mv chromedriver /usr/local/lib/python2.7/site-packages/ /usr/bin

but it said it cannot move so I don't think the others will be affected. Please help or let me know what I could do to fix this.


The script is as simple as this:

import requests

print 'hello world'

And now when I try to install requests, it shows error as below:

[ec2-user@ folder]$ sudo pip install requests
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip import main
ImportError: No module named pip
[ec2-user@ folder]$ sudo which pip
[ec2-user@ folder]$ sudo which python

There must be something wrong with the locations of my python libraries, but I cannot figure out what/when/how I messed with them.

Answer Source

When executing sudo mv chromedriver /usr/local/lib/python2.7/site-packages/ /usr/bin this actually moved the directory site-packages to /usr/bin/ rather than the intended chromedriver.

All that needs to be done is to move the site-packages directory back to it's correct place and you'll be all set.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download