I have a script that will run locally, but not on my Ubuntu server. Other scripts work fine on both platforms, but this specific one throws a import error when I attempt to run it on 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'
Other scripts work fine and I didn't have this problem until I tried using the newspaper library. I have attempted the following:
pip3 install --upgrade newspaper3k
pip3 install --upgrade lxml
adding /usr/local/lib/python3.5/site-packages to $PATH
running on and off of a virtual environment
importing lxml.etree directly within the script
running on python3.5 terminal -
no errors thrown
apt-get remove python3.5,
pip3 uninstall newspaper3k,
pip3 install newspaper3k,
apt-get install python3.5
checked permissions of site-packages folder
checked the default library path that python3.5 uses
ensured the hashbang #!/usr/bin/env python3.5 is at the top of all files
sudo apt-get install python-lxml
I'm stumped here. Any guidance would be much appreciated.
EDIT:
I have also followed the instructions listed here: https://newspaper.readthedocs.io/en/latest/
Everything downloaded correctly except the following:
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'
based on your post, it seems like the problem can be with ubuntu environment differing from your other (mac os?) local environments. I assume that you've gotten newspaper3k lib to install properly on Mac OS environments but not Ubuntu?
Perhaps try the guidance in this post first, ImportError: No module named '_sqlite3' in python3.3
I think the core issue is that your ubuntu env is missing some important underlying packages that these python libs require.
Or maybe:
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
Related
I have installed python3.8 from redhat repo
dnf install python38
on clean CentOS 8. When I run my app.py script the following appears.
Traceback (most recent call last):
File "project/app.py", line 5, in <module>
import instaloader
File "~/.venv/lib/python3.8/site-packages/instaloader/__init__.py", line 16, in <module>
from .instaloader import Instaloader
File "~/.venv/lib/python3.8/site-packages/instaloader/instaloader.py", line 3, in <module>
import lzma
File "/opt/python38/lib/python3.8/lzma.py", line 27, in <module>
from _lzma import *
ModuleNotFoundError: No module named '_lzma'
Note that I have everything tested and working on other fedora 31 system and seems that all the required rpm package are installed in favour lzma to be functioning as I need for.
I'm trying to execute ansible in my system. I guess I messed up something and unable to run ansible. When I run ansible --version, I see the following error:
krishnapatamset:bin krishna.patamsetti$ ansible --version
[WARNING]: log file at /var/log/ansible/ansible.log is not writeable and we cannot create it, aborting
ERROR! Unexpected Exception: No module named markupsafe
the full traceback was:
Traceback (most recent call last):
File "/usr/local/bin/ansible", line 80, in <module>
from ansible.cli.adhoc import AdHocCLI as mycli
File "/usr/local/lib/python2.7/site-packages/ansible/cli/adhoc.py", line 28, in <module>
from ansible.executor.task_queue_manager import TaskQueueManager
File "/usr/local/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 29, in <module>
from ansible.executor.play_iterator import PlayIterator
File "/usr/local/lib/python2.7/site-packages/ansible/executor/play_iterator.py", line 30, in <module>
from ansible.playbook.block import Block
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 27, in <module>
from ansible.playbook.play import Play
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/play.py", line 27, in <module>
from ansible.playbook.base import Base
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/base.py", line 29, in <module>
from jinja2.exceptions import UndefinedError
File "/usr/local/lib/python2.7/site-packages/jinja2/__init__.py", line 33, in <module>
from jinja2.environment import Environment, Template
File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 13, in <module>
from jinja2 import nodes
File "/usr/local/lib/python2.7/site-packages/jinja2/nodes.py", line 19, in <module>
from jinja2.utils import Markup
File "/usr/local/lib/python2.7/site-packages/jinja2/utils.py", line 531, in <module>
from markupsafe import Markup, escape, soft_unicode
ImportError: No module named markupsafe
Can anyone please help me with this situation. Thanks in advance
I even tried pip install markupsafe but still I am unable to get ansible working
Ansible is based on python and there is a python module that's missing called markupsafe
install it via pip, you may need to escalate privileges
pip2 install -I markupsafe
pip2 for python 2.x
-I to ignore and reinstall package if it's already installed
I uninstalled pip and installed it again.
brew uninstall pip
brew doctor
brew install pip
Now we're developing our software on the customer side, and there is:
maestro#UIServer:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION="Ubuntu 9.10"
system is installed. We're not allowed to upgrade this system to a newer version, but we need to use Python 2.7 in our project.
E.g. we have to use pymorphy2 package, but when we're trying to import it into project, we get:
>>> import pymorphy2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/pymorphy2/__init__.py", line 3, in <module>
from .analyzer import MorphAnalyzer
File "/usr/local/lib/python2.7/site-packages/pymorphy2/analyzer.py", line 10, in <module>
from pymorphy2 import opencorpora_dict
File "/usr/local/lib/python2.7/site-packages/pymorphy2/opencorpora_dict/__init__.py", line 4, in <module>
from .storage import load_dict as load
File "/usr/local/lib/python2.7/site-packages/pymorphy2/opencorpora_dict/storage.py", line 24, in <module>
from pymorphy2.utils import json_write, json_read
File "/usr/local/lib/python2.7/site-packages/pymorphy2/utils.py", line 5, in <module>
import bz2
ImportError: No module named bz2
Ok, we're trying to install libbz2-dev:
sudo apt-get install libbz2-dev
end getting this:
ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
dpkg: error processing python-pip (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
python-pip
E: Sub-process /usr/bin/dpkg returned an error code (1)
How to avoid this problem?
Thanks in advance!
Download python, build and install using :
$ ./configure
$ make
$ make install
I am assuming you have build-essential installed or at least gcc. You can customize installation by passing prefix=/path/where/you/want/python/installed and other flags to make.
I am trying to install CKAN onto Ubuntu 13.10. (64bit) following these instructions. Python 2.7.5+ is installed on the machine. The following errors stop me from installing the CKAN package:
$ sudo dpkg -i python-ckan_2.2_amd64.deb
Selecting previously unselected package python-ckan.
(Reading database ... 289528 files and directories currently installed.)
Unpacking python-ckan (from python-ckan_2.2_amd64.deb) ...
Setting up python-ckan (2.2-1) ...
Traceback (most recent call last):
File "/usr/lib/ckan/default/bin/paster", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/ \
distribute-0.6.24-py2.7.egg/pkg_resources.py", line 16, in <module>
import sys, os, zipimport, time, re, imp, types
File "/usr/lib/ckan/default/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/usr/lib/ckan/default/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/usr/lib/ckan/default/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/usr/lib/ckan/default/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
System start/stop links for /etc/init.d/nginx already exist.
System start/stop links for /etc/init.d/apache2 already exist.
ERROR: Site ckan_default does not exist!
ERROR: Site datapusher does not exist!
Finally, I installed CKAN from source as suggested by the documentation:
This is the quickest and easiest way to install CKAN, but it requires Ubuntu 12.04 64-bit.
I'm trying to install couchdb app on debian using the following command
couchapp push http://user:pass#localhost:5984/acra-appname
and I'm having the following error output:
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/restkit/__init__.py", line 9, in <module>
from restkit.conn import Connection
File "/usr/local/lib/python2.6/dist-packages/restkit/conn.py", line 14, in <module>
from socketpool import Connector
ImportError: No module named socketpool
Traceback (most recent call last):
File "/usr/local/bin/couchapp", line 7, in <module>
from couchapp.dispatch import run
File "/usr/local/lib/python2.6/dist-packages/couchapp/dispatch.py", line 10, in <module>
import couchapp.commands as commands
File "/usr/local/lib/python2.6/dist-packages/couchapp/commands.py", line 15, in <module>
from couchapp import clone_app
File "/usr/local/lib/python2.6/dist-packages/couchapp/clone_app.py", line 15, in <module>
from couchapp.errors import AppError
File "/usr/local/lib/python2.6/dist-packages/couchapp/errors.py", line 7, in <module>
from restkit import ResourceError
ImportError: cannot import name ResourceError
As far as I understand the error is:
ImportError: No module named socketpool
How can I install this module or how to resolve the problem?
As Ifthikhan sugessted: Install it using a package manager such as apt-get and thereafter using pip you can install socketpool.
I had this problem when installing couchapp. I used pip to install it, and I thought it completed, but when I ran it I had the ImportError problem. Turns out the pip install didn't succeed and I first needed to:
apt-get install python-dev
Then when I did a
pip install couchapp
all of the dependencies were installed and couchapp ran without a problem.