我使用Ubuntu 18.04,并且使用Django和Apache。我想在其中包括一个Selenium脚本。通过pip安装的其他外部库(例如ics)也会出现问题,但不是全部(例如scrapy)都安装。
bash命令正常工作。
sudo scrapy runspider -s LOG_ENABLED=False -a category=electronics -a domain=system /home/chef/Desktop/synology/selenium/ginger.py > /home/chef/Desktop/synology/selenium/output.txt 2>> /home/chef/Desktop/synology/selenium/output.txt
通过Django(通过另一个目录)进行的集成提供:
ModuleNotFoundError at /
No module named 'selenium'
Request Method: GET
Request URL: http://192.168.111.174/
Django Version: 2.1.2
Exception Type: ModuleNotFoundError
Exception Value:
No module named 'selenium'
Exception Location: /home/chef/Desktop/Immo/Immo/Immo/ginger.py in <module>, line 1
Python Executable: /usr/bin/python3
Python Version: 3.6.7
Python Path:
['/usr/bin/python3',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages',
'/home/chef/Desktop/Immo/Immo']
脚本开始于:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import scrapy
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from scrapy.http import Request
import time
命令行有效:
chef@ubuntu:~/Desktop/Immo/Immo/Immo$ which python3
/usr/bin/python3
chef@ubuntu:~/Desktop/Immo/Immo/Immo$ cat /etc/apache2/apache2.conf |egrep WSGI
WSGIPythonPath /usr/bin/python3
chef@ubuntu:~/Desktop/Immo/Immo/Immo$ python3 -m pip search selenium | egrep -B1 'INSTALLED|LATEST'
selenium (3.141.0) - Python bindings for Selenium
INSTALLED: 3.141.0 (latest)
chef@ubuntu:~/Desktop/Immo/Immo/Immo$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ics import Calendar, Event
>>> from selenium import webdriver
>>>
我在控制台中尝试过
export PYTHONPATH=/usr/local/lib/python3.6
我在wsgi.py中尝试过:
path='/home/chef/Desktop/Immo/Immo'
if path not in sys.path:
sys.path.append(path)
sys.path.append('/usr/local/lib/python3.6')
我必须更改什么?