我有一个脚本可以在本地运行,但不能在我的Ubuntu服务器上运行。其他脚本在这两个平台上都可以正常工作,但是当我尝试在Ubuntu上运行该特定脚本时,将引发导入错误。
root@ip-xxx-xx-xx-xxx:~# /usr/bin/python3.5 /opt/script_folder/main.py
Traceback (most recent call last):
File "/opt/script_folder/main.py", line 2, in <module>
import process
File "/opt/script_folder/process.py", line 25, in <module>
from tools.getImages import getImages
File "/opt/script_folder/tools/getImages.py", line 5, in <module>
from newspaper import Article
File "/usr/local/lib/python3.5/site-packages/newspaper/__init__.py", line 10, in <module>
from .api import (build, build_article, fulltext, hot, languages,
File "/usr/local/lib/python3.5/site-packages/newspaper/api.py", line 14, in <module>
from .article import Article
File "/usr/local/lib/python3.5/site-packages/newspaper/article.py", line 15, in <module>
from . import network
File "/usr/local/lib/python3.5/site-packages/newspaper/network.py", line 14, in <module>
from .configuration import Configuration
File "/usr/local/lib/python3.5/site-packages/newspaper/configuration.py", line 15, in <module>
from .parsers import Parser
File "/usr/local/lib/python3.5/site-packages/newspaper/parsers.py", line 10, in <module>
import lxml.etree
ImportError: No module named 'lxml.etree'
其他脚本工作正常,直到尝试使用报纸库之前,我没有这个问题。我尝试了以下操作:
我被困在这里。任何指导将不胜感激。
编辑: 我也按照此处列出的说明进行操作:https://newspaper.readthedocs.io/en/latest/ 正确下载所有内容,但以下内容除外:
root@ip-xxx-xx-xx-xxx:~# curl https://raw.githubusercontent.com/codelucas/newspaper/master/download_corpora.py | python3
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 100 657 100 657 0 0 9387 0 --:--:-- --:--:-- --:--:-- 10265
Traceback (most recent call last):
File "<stdin>", line 6, in <module>
File "/usr/local/lib/python3.5/site-packages/nltk/__init__.py", line 137, in <module>
from nltk.stem import *
File "/usr/local/lib/python3.5/site-packages/nltk/stem/__init__.py", line 29, in <module>
from nltk.stem.snowball import SnowballStemmer
File "/usr/local/lib/python3.5/site-packages/nltk/stem/snowball.py", line 32, in <module>
from nltk.corpus import stopwords
File "/usr/local/lib/python3.5/site-packages/nltk/corpus/__init__.py", line 66, in <module>
from nltk.corpus.reader import *
File "/usr/local/lib/python3.5/site-packages/nltk/corpus/reader/__init__.py", line 105, in <module>
from nltk.corpus.reader.panlex_lite import *
File "/usr/local/lib/python3.5/site-packages/nltk/corpus/reader/panlex_lite.py", line 15, in <module>
import sqlite3
File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
答案 0 :(得分:0)
根据您的帖子,看来问题出在ubuntu环境可能不同于您的其他(mac os?)本地环境。我认为您已经获得了报纸3k lib可以在Mac OS环境中正确安装,但不能在Ubuntu上安装
?也许首先尝试这篇帖子中的指南,ImportError: No module named '_sqlite3' in python3.3
我认为核心问题是您的ubuntu env缺少了这些python库所需的一些重要底层软件包。
或者:
apt-get install sqlite3
sqlite3 -version
apt-get install python-pysqlite2
apt-get install python-pysqlite2-dbg
apt-get install libsqlite3-dev
apt-get install sqlite
pip install pysqlite