I have upgraded my ubuntu from 16.04 to 18.04 and then to 19.04. I've noticed that my virtualenvs stopped working and located the problem in distutils.
I've installed python3-distutils and I can run python3 > import distutils just fine, because this relates to python 3.7.
I can also do the same with python (2.7).
The problem is that a lot of my envs are python 3.6 where if I run import distutils I get:
Python 3.6.3 (default, Oct 6 2017, 08:44:35)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import distutils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/emihir0/mjartan/lib/python3.6/distutils/__init__.py", line 25, in <module>
from distutils import dist, sysconfig
ImportError: cannot import name 'dist'
>>>
How can I resolve this?
The same goes for when I try to make a new venv through pycharm. I can make a new venv for both 3.7 and 2.7, but as soon as I try to make 3.6 I get:
Traceback (most recent call last):
File "/tmp/tmpb_tuwex1pycharm-management/setuptools-40.8.0/setup.py", line 11, in <module>
import setuptools
File "/tmp/tmpb_tuwex1pycharm-management/setuptools-40.8.0/setuptools/__init__.py", line 6, in <module>
import distutils.core
ModuleNotFoundError: No module named 'distutils.core'
And well, the main problem of course is that when I try to just run pip in my virtualenv, I get:
Traceback (most recent call last):
File "/home/emihir0/venv_name/bin/pip", line 7, in <module>
from pip._internal import main
File "/home/emihir0/venv_name/lib/python3.6/site-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/emihir0/venv_name/lib/python3.6/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/emihir0/venv_name/lib/python3.6/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/home/emihir0/venv_name/lib/python3.6/site-packages/pip/_internal/cli/cmdoptions.py", line 17, in <module>
from pip._internal.locations import USER_CACHE_DIR, src_prefix
File "/home/emihir0/venv_name/lib/python3.6/site-packages/pip/_internal/locations.py", line 10, in <module>
from distutils import sysconfig as distutils_sysconfig
File "/home/emihir0/venv_name/lib/python3.6/distutils/__init__.py", line 25, in <module>
from distutils import dist, sysconfig
ImportError: cannot import name 'dist'
EDIT:
I've fixed it by downgrading my python3-distutils to:
https://ubuntu.pkgs.org/18.04/ubuntu-main-i386/python3-distutils_3.6.5-3_all.deb.html
However, this is not a proper solution. How shall one fix this properly?
Related
I used to use pyenv as my version manager but it had too much trouble installing packages so I'm moving over to virtualenv. So when I activate my virtual environment and write: which python I get:
/Users/kylefoley/codes/venv/bin/python
But when I actually use python it seems that it is still using pyenv. For example:
(venv) Admins-MacBook-Pro-4:~ kylefoley$ python
Python 3.8.0 (default, Nov 28 2019, 02:43:40)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'Tk'
>>> import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'Tkinter'
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kylefoley/.pyenv/versions/3.8.0/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
I'm not trying to fix the problem of not being able to use Tkinter rather I just want to understand why this line:
File "/Users/kylefoley/.pyenv/versions/3.8.0/lib/python3.8/tkinter/__init__.py", line 36, in <module>
is coming up.
It's because I created the virtual environment when my version management was still pyenv. If I eliminate that version management, then I do not get the file pyenv.cfg but instead get the file: pip selfcheck.json which is located in the virtual environment directory together which lib, bin and include.
I installed Python 3.7.4 from sources to a local folder. Installation did not produce any errors, but the binaries do not work.
That's what I did to install and setup the software
./configure --prefix=/usr/local/python3.7.4
make -j 8 install
export PYTHONHOME="/usr/local/python3.7.4/"
export PYTHONPATH="/usr/local/python3.7.4/lib/python3.7/site-packages/"
That's what I get when attempt to run python3
/usr/local/python3.7.4/bin/python3
Python 3.7.4 (default, Sep 4 2019, 19:14:06)
[GCC 4.8.3 20140627 [gcc-4_8-branch revision 212064]] on linux
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/etc/pythonstart", line 7, in <module>
import readline
ModuleNotFoundError: No module named 'readline'
and this is what I get from pip3:
/usr/local/python3.7.4/bin/pip3
Traceback (most recent call last):
File "/usr/local/python3.7.4/bin/pip3", line 6, in <module>
from pip._internal import main
File "/usr/local/python3.7.4/lib/python3.7/site-packages/pip/_internal/__init__.py", line 19, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
File "/usr/local/python3.7.4/lib/python3.7/site-packages/pip/_vendor/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/usr/local/python3.7.4/lib/python3.7/site-packages/pip/_vendor/urllib3/connectionpool.py", line 7, in <module>
from socket import error as SocketError, timeout as SocketTimeout
File "/usr/local/python3.7.4/lib/python3.7/socket.py", line 49, in <module>
import _socket
ModuleNotFoundError: No module named '_socket'
I feel that the core of the problem is the local installation.
I am sorry if my question is trivial. I tried googling it with no success.
Thank you for your time.
The problem was resolved by adding more paths to the PYTHONPATH variable
export PYTHONPATH="/usr/local/python3.7.4/lib/python3.7/site-packages/:/usr/local/python3.7.4/:/usr/local/python3.7.4/lib64/python3.7/lib-dynload/"
I'm having problems using the requests library. I used pip to install it and I also intalled through github and the installation goes just fine. But when I try to import the lib, I get this error:
Python 2.7.14+ (default, Mar 13 2018, 15:23:44)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/crypto.py", line 12, in <module>
from cryptography import x509
File "/usr/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 8, in <module>
from cryptography.x509.base import (
File "/usr/lib/python2.7/dist-packages/cryptography/x509/base.py", line 16, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "/usr/lib/python2.7/dist-packages/cryptography/x509/extensions.py", line 24, in <module>
from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
File "/usr/lib/python2.7/dist-packages/cryptography/x509/general_name.py", line 18, in <module>
from cryptography.x509.name import Name
File "/usr/lib/python2.7/dist-packages/cryptography/x509/name.py", line 28, in <module>
_ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
TypeError: 'type' object is not iterable
>>>
I saw in another post a person saying something about the PATH, but I didn't understand... Something related to a conflict between /usr/bin and /usr/local/bin. I don't know if this have something to do with it.
I also have used pip2.7 to install the lib and it shows in the pip list command. I'd appreciate any help.
The issue is in the cryptography module. It can also be found on the github page. The solution seems to be that you need to replace the enum package:
pip uninstall enum
pip install enum34
Note that you need to use sudo pip if you are using packages from /usr/
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..
I've been learning python over the past couple of days from Head First Python.
I've reached a point where I have to build a distribution package of a module I've made, called nester, and install it on my system. After installing the module I have to import it into a script and use a function from the imported module.
When trying to import the module from any folder other than the one where I saved the original nester.py, I get the following error (which suggests to me the module wasn't installed correctly):
james#james-Inspiron-1764:~$ python3.3
Python 3.3.0 (default, Sep 29 2012, 17:14:58)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nester
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'nester'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 4, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 21, in <module>
import apt_pkg
ImportError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'nester'
>>>
This is how I've built and installed the module:
james#james-Inspiron-1764:~/python/headfirst/chapter2/nester$ python3.3 setup.py sdist
/usr/lib/python3.3/distutils/dist.py:257: UserWarning: Unknown distribution option: 'pymodules'
warnings.warn(msg)
running sdist
running check
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)
warning: sdist: standard file not found: should have one of README, README.txt
writing manifest file 'MANIFEST'
creating nester_jc-1.4.0
making hard links in nester_jc-1.4.0...
hard linking setup.py -> nester_jc-1.4.0
Creating tar archive
removing 'nester_jc-1.4.0' (and everything under it)
james#james-Inspiron-1764:~/python/headfirst/chapter2/nester$ sudo python3.3 setup.py install
[sudo] password for james:
/usr/lib/python3.3/distutils/dist.py:257: UserWarning: Unknown distribution option: 'pymodules'
warnings.warn(msg)
running install
running build
running install_egg_info
Removing /usr/local/lib/python3.3/dist-packages/nester_jc-1.4.0.egg-info
Writing /usr/local/lib/python3.3/dist-packages/nester_jc-1.4.0.egg-info
I can successfully import nester if python is started from inside ~/python/headfirst/chapter2/nester, but not if I start from any other location.
Is this a problem with the way I'm installing the module, or is it a problem with my python installation?