in ubuntu 18.04, when i change default python from python 3.6 to other version by this command:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
or when i remove python 3.6 and install other version netplan apply not working and result this error:
File "/usr/sbin/netplan", line 20, in <module>
from netplan import Netplan
File "/usr/share/netplan/netplan/__init__.py", line 18, in <module>
from netplan.cli.core import Netplan
File "/usr/share/netplan/netplan/cli/core.py", line 24, in <module>
import netplan.cli.utils as utils
File "/usr/share/netplan/netplan/cli/utils.py", line 25, in <module>
import netifaces
ModuleNotFoundError: No module named 'netifaces'
and command pip install netifaces has some errors.
I faced the same issue before with vagrant. If you use update-alternatives to make python3 alias points to another version of Python, vagrant will not work. You cannot use update-alternatives to change the alias of Python3.
For some reason I lost my python configuration after an update made by my ubuntu server,solved by:
Checking if I could import the module so on CLI:
python
import python
After getting the same message I realize my python environment was falling to use the modules even when it all showed up as installed I went ahead and "upgrade" the python modules:
python pip install --upgrade pip
python pip install --upgrade netifaces
python pip install --upgrade "any module you need to use for your script"
And just like that modules were recognized updated and properly install.
tl;dr: Create a link netifaces.so to netifaces.cpython-36m-x86_64-linux-gnu.so in /usr/lib/python3/
In /usr/lib/python3/dist-packages/ is only a module for python3.6:
vagrant#ubuntu18.04:~$ find /usr/lib/python3/dist-packages/ -type f -name netifaces\*
/usr/lib/python3/dist-packages/netifaces.cpython-36m-x86_64-linux-gnu.so
That's why importing 'netifaces' failes for python3.8 while it works for python3.6:
vagrant#ubuntu18.04:~$ python3.6 -c 'import netifaces; print("works!")'
works!
vagrant#ubuntu18.04:~$ python3.8 -c 'import netifaces; print("works!")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'netifaces'
One can link to it with a more unspecific name so python3.8 can find and use it:
vagrant#ubuntu18.04:~$ sudo ln -s /usr/lib/python3/dist-packages/netifaces.cpython-36m-x86_64-linux-gn
u.so /usr/lib/python3/dist-packages/netifaces.so
vagrant#ubuntu18.04:~$ python3.8 -c 'import netifaces; print("works!")'
works!
Hint: I had to do the same for apt_pkg.so → apt_pkg.cpython-36m-x86_64-linux-gnu.so
Related
Can't import Quartz package.
I have installed it with this command pip install pyobjc-framework-Quartz. Tried reinstalling python, also tried python -m pip install .... With python2 or sudo python3, everything works fine but python3 is giving me this error message every time I try importing Quartz
Python version - 3.10.4
Mac version - Big Sur 11.6.5
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import Quartz
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Quartz/__init__.py", line 6, in <module>
import AppKit
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/AppKit/__init__.py", line 10, in <module>
import Foundation
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Foundation/__init__.py", line 9, in <module>
import CoreFoundation
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/CoreFoundation/__init__.py", line 9, in <module>
import objc
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/__init__.py", line 6, in <module>
from . import _objc
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so, 2): Symbol not found: _FSPathMakeRef
Referenced from: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so
For investigation purposes, can you try :
cd /tmp
python3 -m venv venv
source venv/bin/activate
pip install pyobjc-framework-Quartz
python your-script.py
Can you try this to see if it works :
env -i /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 my_script.py
You may have files only accessible by root, try to change ownership:
sudo chown -R $(id -u):$(id -g) /Library/Frameworks/Python.framework/Versions/3.10
and run env -i ... again.
If you run :
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -c 'import sys;print(sys.path)'
sudo /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -c 'import sys;print(sys.path)'
Is there any difference between the two ?
Try following to see if it improves :
sudo /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -m pip install pyobjc-framework-Quartz
Try this to see if there is anything unusual :
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -X importtest -v -c 'import Quartz'
You might need to try:
python3 -m pip install [...]
Hope this will hope.
This question already has an answer here:
How to install pip in Python 2.7 on macOS Big Sur?
(1 answer)
Closed 1 year ago.
User#Admins-MacBook-Pro ~ % pip install xq
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==21.1.2', 'console_scripts', 'pip')()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2440, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Library/Python/2.7/site-packages/pip-21.1.2-py2.7.egg/pip/__init__.py", line 1, in <module>
from typing import List, Optional
ImportError: No module named typing
If you get above error pip install xq .Try with below command :
sudo python3 -m pip install --upgrade --force-reinstall pip
brew install python --> install the latest Python.
ls -l /usr/local/bin/python* --> List all Python versions installed on your system.
ln -s -f /usr/local/bin/python[your-latest-version-just-installed] /usr/local/bin/python --> Change default Python version to the latest version.
E.g: ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python
Restart terminal.
python --version --> Check Python version default again.
Ref: https://dev.to/malwarebo/how-to-set-python3-as-a-default-python-version-on-mac-4jjf
Like it if it helps you
try the following in your mac terminal:
/usr/local/opt/python#3.9/bin/python3.9 -m pip install --upgrade pip
then:
pip install typing
From the docs:
For package maintainers, it is preferred to use
typing;python_version<"3.5" if your package requires it to support
earlier Python versions. This will avoid shadowing the stdlib typing
module when your package is installed via pip install -t . on Python
3.5 or later.
xq might need python3 for smooth running, did not check it though. Maybe you can elaborate a little of your expectation in the question
Background: I'm currently running Elementary OS Hera(Ubuntu 18.04 LTS). The distribution came with Python 3.6.9. At some point I installed Python 3.7.5...this is when the issue(s) started.
Problem: I'm attempting to install PyQt5 which keeps defaulting to the older version for some reason. I ensured that Python3 was referencing the newer version:
Wick:~$ python3 --version
Python 3.7.5
I also ensured that python3.7 was the primary version:
Wick:~$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.7 2 auto mode
1 /usr/bin/python3.6 1 manual mode
* 2 /usr/bin/python3.7 2 manual mode
BUT when I run sudo apt-get install -y python3-pyqt5 . It still continues to install to the 3.6 version. This can be verified via:
:~$ python3 -c "from PyQt5.QtCore import QSettings; print('done')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.QtCore'
AND the kicker
:~$ python3.6 -c "from PyQt5.QtCore import QSettings; print('done')"
done
OR
:~$ python3.7 -c "from PyQt5.QtCore import QSettings; print('done')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.QtCore'
Any assistance you can offer is greatly appreciated. I'm losing my mind.
p.s. apologies in advance for being a newbie
The package only depends on python3.6: https://packages.ubuntu.com/bionic/python3-pyqt5. It will be installed because it is a prerequisite.
This was resolved by #chepner:
"I would recommend using a virtual environment created with /usr/bin/python3.7, >then install pyqt5 there using pip rather than trying to install it via your >package manager."
Thanks so much!
I have Python 2.7.14. I know that Python 2 is deprecated but I don't have choice for the moment.
I tried to install openpyxl library.
I downloaded and extracted the .tar.gz. The version downloaded is 3.0.3.
When I run python setup.py install, I'm facing the following error:
Traceback (most recent call last):
File "setup.py", line 28, in <module>
from importlib.util import module_from_spec, spec_from_file_location
ImportError: No module named util
How can I solve this issue for Python 2.7.14?
From the openpyxl release history, the last version compatible with Python2.7 is 2.6.4:
https://openpyxl.readthedocs.io/en/stable/changes.html#id16
2.6.4 (2019-09-25)
Final release for Python 2.7 ––––––––––––––––––––––––––––
Starting openpyxl 3.0.0, it is Python-3 only.
So, you need to install a specific older version.
Using pip:
$ python -V
Python 2.7.17
$ python -m pip install openpyxl==2.6.4
Using the downloadable tar.gz from PyPi:
$ wget https://files.pythonhosted.org/packages/d6/26/eb28e975b7a37aad38d7ec4f7a0f652bdee6ecf36e6bd06f473c5af9b87b/openpyxl-2.6.4.tar.gz
$ mkdir openpyxl-2.6.4
$ tar -xvzf openpyxl-2.6.4.tar.gz -C openpyxl-2.6.4
$ cd openpyxl-2.6.4
$ python setup.py install
I'm running VPS with ubuntu:
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
I tried to upgrade Python to 2.7.16 from 2.7.6.
Just after upgrade Gunicorn library failed to start with
Traceback (most recent call last):
File "/home/user/bin/python-2.7/bin/gunicorn", line 7, in <module>
from gunicorn.app.wsgiapp import run
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 9, in <module>
from gunicorn.app.base import Application
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/app/base.py", line 12, in <module>
from gunicorn import util
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/util.py", line 12, in <module>
import pkg_resources
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 82, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/pkg_resources/extern/__init__.py", line 61, in load_module
"distribution.".format(**locals())
ImportError: The 'packaging.requirements' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
I was told that it could be some setuptools issue, so I renewed them with
python -m ensurepip
Looking in links: /tmp/tmp98U8zf
Requirement already satisfied: setuptools in ./bin/python-2.7/lib/python2.7/site-packages (41.1.0)
Requirement already satisfied: pip in ./bin/python-2.7/lib/python2.7/site-packages (19.2.2)
(no changes)
I tried to do
pip install packaging
(no changes)
or downgrade setuptools to 19.2 (as suggested in Python 2.7 The 'packaging' package is required; normally this is bundled with this package)
and got
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/config.py", line 8, in <module>
import copy
File "/home/user/bin/python-2.7/lib/python2.7/copy.py", line 52, in <module>
import weakref
File "/home/user/bin/python-2.7/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
Is there any working way to upgrade to 2.7.16 python in my case?
UPD:
I upgraded python with it with
wget https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tgz
make clean && ./configure --enable-unicode=ucs4 --enable-shared --prefix=/home/user/bin/python-2.7/ --with-ensurepip=install && make && make install
pip install -r ~/django/django_projects/requirements.txt
pip freeze: https://www.pastiebin.com/5d592ea701503
Thanks.
Scenario
First: When trying to execute a Python script, the following error message appears:
ImportError: The 'packaging.requirements' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
Second: When trying to check the version of setuptools with pip show setuptools (or when using any other pip command), the next error message appears:
ImportError: cannot import name _remove_dead_weakref
Reason
This is because the current Python installation is somehow screwed up. In my case the mess was caused by an upgrade from Ubuntu 16.04 to Ubuntu 18.04.
Solution
With Virtual Environment
In the best case you were already using a virtual environment (this was my case). The solution here would be to recreate/setup your venv again (step-by-step):
$ cd /path/to/your/venv
# remove your old venv
$ rm -rf ./*
# create a new one
$ /usr/bin/virtualenv . --python=YOUR-PYTHON-VERSION
# activate venv
$ source bin/activate
# verify the correct python version is installed
$ python --version
For example replace YOUR-PYTHON-VERSION with python2.7 or python3.7.
After recreating your venv the problem should be fixed and you should be able to use pip again.
Without Virtual Environment
I think the best way to fix the problem would be to completely uninstall all non-default Python versions (for example Ubuntu 18.04 comes with Python 3.6+) and then make a clean reinstall of all other Python versions needed.
Try upgrading pip by typing:
pip install --upgrade pip