python3.8 import manager cant find lzma std lib - python

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.

Related

Import error with Ubuntu script using newspaper module

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

"No module named zlib" error anytime I use pip

I'm using terminal on mac, and anytime I attempt to use pip, I get the following error message telling me that it cannot find a module named zlib:
$ pip --version
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/__init__.py", line 27, in <module>
from . import urllib3
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 42, in <module>
from .response import HTTPResponse
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 3, in <module>
import zlib
ModuleNotFoundError: No module named 'zlib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/bin/pip", line 7, in <module>
from pip import main
File "/usr/local/lib/python3.6/site-packages/pip/__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/__init__.py", line 62, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/__init__.py", line 29, in <module>
import urllib3
File "/usr/local/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 36, in <module>
from .response import HTTPResponse
File "/usr/local/lib/python3.6/site-packages/urllib3/response.py", line 3, in <module>
import zlib
ModuleNotFoundError: No module named 'zlib'
I've read several SO posts with the same error message, and have tried their solutions, including attempting to install zlib using homebrew, which fails, and updating my Xcode developer tools. I also installed pip earlier using python get-pip.py, and it said it installed successfully.
The reason I need pip is to install a package for use on python 2.7, but doing $ pip install "package-name" produces the same error as above. I have both Python 2 and 3 installed on my machine, if that helps. I'm kind of new to pip and using the command line in general, and I'm super confused; if anyone could help me out I'd really appreciate it.
This is the OP. I was able to fix the issue, and wanted to post my solution here in case it would help others.
Essentially I believe it occurred because Python2 is default on my machine, but pip is by default pointing to resources pertaining to Python3, or something like that. Doing pip2 --version instead provided the expected response.

How can I fix this pip error?

I am having some trouble understanding and fixing this issue in my python installation. Hopefully someone can help me wrap my head around this..?
Python itself runs (ie: the python command produces the expected REPL). When I try to use pip (pip search, pip install, ...) I get the following traceback (apparently there are core modules missing..?!):
Traceback (most recent call last):
File "/usr/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 26, in <module>
import zipfile
File "/usr/lib/python3.6/zipfile.py", line 13, in <module>
import shutil
File "/usr/lib/python3.6/shutil.py", line 13, in <module>
import tarfile
File "/usr/lib/python3.6/tarfile.py", line 48, in <module>
import struct
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
But how can that be?
I've tried reinstalling python (through pacman) to no avail. Ditto for python-pip.
Perhaps the exception is misleading..?
What's with the core module struct importing a private version of itself that doesn't exist?! How could such an omission exist? Everyone's python 3.6 would be broken.. no?
sys.path = ['', '/code/scott/Py/Path', '/usr/lib/python3.6/Tools/scripts', '/usr/lib/python3.6/site-packages', '/usr/lib/python3.6', '/usr/lib/python3.6/lib/python36.zip', '/usr/lib/python3.6/lib/python3.6', '/usr/lib/python3.6/lib/python3.6/lib-dynload']
Python version:
Python 3.6.0 (default, Jan 16 2017, 12:12:55) [GCC 6.3.1 20170109] on
linux
Pip version: 9.0.1-2 (Built: 24/12/2016 06:47:25)
OS: Manjaro Linux (Arch Linux + KDE)
Kernel version: 4.9.9-1-MANJARO (from KInfocentre)
python and pip (python-pip) installed through pacman (arch package manager) via the commands:
sudo pacman -S python
sudo pacman -S python-pip
Ah! Importing struct from inside python produces the same error:
import struct
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
...What information would be helpful? I can add to my question..

CKAN installation errors: Sites ckan_default and datapusher do not exist

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.

ImportError: cannot import name ResourceError

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.

Categories

Resources