Python multi-version error _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE - python

I have an error when running app with python3.5
Traceback (most recent call last):
File "/usr/local/bin/face_recognition", line 7, in <module>
from face_recognition.cli import main
File "/usr/local/lib/python3.5/site-packages/face_recognition/__init__.py", line 7, in <module>
from .api import load_image_file, face_locations, face_landmarks, face_encodings, compare_faces, face_distance
File "/usr/local/lib/python3.5/site-packages/face_recognition/api.py", line 4, in <module>
import dlib
File "/usr/local/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
from .dlib import *
ImportError: /usr/local/lib/python3.5/site-packages/dlib/dlib.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
I can see that libboost is the problem, I compiled it with appropriate version of python and set python root as well but still have an error. What did I miss?

I also meet this kind of problem. On my Mac, I have installed a version of boost 1.58 from source code.
When I try to install dlib by following command:
brew install cmake
brew install boost
brew install boost-python --with-python3
sudo pip3 install numpy
sudo pip3 install scipy
sudo pip3 install scikit-image
sudo pip3 install dlib
I think dlib use the wrong version of boost on my Mac.
Here is my solution:
try to delete boost using brew uninstall, and delete all related boost include and lib files from /usr/local/include & /usr/local/lib.
reinstall above brew & pip3 commands to reinstall all related libraries.
After this two steps, my Mac now can use dlib under Python3 correctly.

Related

ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)

I installed pip3 using sudo apt-get install python3-pip after that when I run the following command to install django sudo pip3 install django I get this error:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in
from pip import main
File "/usr/lib/python3/dist-packages/pip/init.py", line 14, in
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/init.py", line 23, in
from pip.locations import (
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in
from distutils import sysconfig
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/init.py)
How do I fix this?
I have tried recently manually installing python3.9 version in my Ubuntu from 3.6 version using apt install python3.9. Then pip3 was broken. The issue is because distutils were not build for the 3.9 version.
So in my case I ran apt install python3.9-distutils to resolve my issue.
In your case make sure to modify 3.x version in distutils command.
This helped but then I got another error: ImportError: No module named 'pip._internal'
The following fixed it:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

ImportError: The 'packaging.requirements' package is required

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

Ubuntu 18.04 LTS install cocoapi

OS:Ubuntu 18.04 LTS
Python Environment = 3.6.8 (System default version)
I followed this link to install cocoapi.
However, it shows the error below:
ubuntu:~/cocoapi-master/PythonAPI$ make
python setup.py build_ext --inplace
Traceback (most recent call last):
File "setup.py", line 2, in <module>
import numpy as np
ImportError: No module named numpy
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 1
I have already installed the needed dependencies mentioned in objection_detection/g3doc/installation.md.
I have also installed Cython and Numpy.
Could somebody help me fix this issue? Thanks in advance.
I run this code
python3 setup.py build_ext --inplace
It doesn't show error.
However, when I tried to run a Tensorflow/models/research/object_detection/model_main.py, it shows error again.
Command line:
ubuntu:~/PycharmProjects/PedestrianDetection$ python object_detection/model_main.py --pipeline_config_path=pretrained/pipeline.config --model_dir=train --num_train_steps=1000 --sample_1_of_n_eval_examples=1 --alsologtostderr
Error:
Traceback (most recent call last):
File "object_detection/model_main.py", line 26, in <module>
from object_detection import model_lib
File "/home/yantong/PycharmProjects/PedestrianDetection/object_detection/model_lib.py", line 28, in <module>
from object_detection import eval_util
File "/home/yantong/PycharmProjects/PedestrianDetection/object_detection/eval_util.py", line 28, in <module>
from object_detection.metrics import coco_evaluation
File "/home/yantong/PycharmProjects/PedestrianDetection/object_detection/metrics/coco_evaluation.py", line 20, in <module>
from object_detection.metrics import coco_tools
File "/home/yantong/PycharmProjects/PedestrianDetection/object_detection/metrics/coco_tools.py", line 47, in <module>
from pycocotools import coco
File "/home/yantong/PycharmProjects/PedestrianDetection/pycocotools/coco.py", line 55, in <module>
from . import mask as maskUtils
File "/home/yantong/PycharmProjects/PedestrianDetection/pycocotools/mask.py", line 3, in <module>
import pycocotools._mask as _mask
ModuleNotFoundError: No module named 'pycocotools._mask'
Under ~/PycharmProjects/PedestrianDetection/pycocotools, I have
cocoeval.py coco.py __init__.py mask.py __pycache__
cocoeval.py.bak coco.py.bak _mask.c _mask.pyx
I'm wondering why it shows No module named 'pycocotools._mask' as well.
According to #Joe A 's guidance, finally make pycocotools by prompting:
pip3 install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
It will be installed in the Ubuntu path /home/USERNAME/.local/lib/python3.6/site-packages
Enter the path /home/USERNAME/.local/lib/python3.6/site-packages
Using Terminal to cd the path above.
NOTICE: USERNAME means your account name on Ubuntu (for me is yantong), replace it with yours.
Copy the downloaded pycocotools from the Step1-2 to your code package.
cp -r pycocotools YOUR_PACKAGE_PATH
NOTICE: You'd better replace YOUR_PACKAGE_PATH with your package's absolute path.
Test
Test by open a Python3 script and prompt:
from pycocotools.coco import COCO
from pycocotools import mask as maskUtils
Press ENTER, if not with error, congrats!
The problem might be the gcc version or installations in your system, follow this if the above solutions fail.
here's how I did it successfully! (the reason is the gcc version)
install the dependencies: cython (pip install python), opencv (pip install opencv-python)
check the gcc version by this command: gcc --version
your output will be like this 'Command 'gcc' not found, but can be installed with:
sudo apt install gcc
'
Type the below commands to install the gcc:
sudo apt update
sudo apt install build-essential
sudo apt-get install manpages-dev
now check again the gcc version(step2)
if you get below output
'gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.'
now run the code for pycocotools installations:
pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"
finally wait to check if the installation is successful :
'Successfully installed pycocotools-2.0'

Unable to install rodeo or spyder in my Ubuntu?

I'm trying to install an IDE for native ML/DA work but both of the top IDEs (spyder and rodeo) dont install on my system.
syder installed using python3.5 -m pip install spyder
but when I try to run spyder from Terminal using spyder I get the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/qtpy/__init__.py", line 119, in <module>
from PySide import __version__ as PYSIDE_VERSION # analysis:ignore
ImportError: No module named 'PySide'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/spyder", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/spyder/app/start.py", line 103, in main
from spyder.app import mainwindow
File "/usr/local/lib/python3.5/dist-packages/spyder/app/mainwindow.py", line 49, in <module>
requirements.check_qt()
File "/usr/local/lib/python3.5/dist-packages/spyder/requirements.py", line 39, in check_qt
import qtpy
File "/usr/local/lib/python3.5/dist-packages/qtpy/__init__.py", line 125, in <module>
raise PythonQtError('No Qt bindings could be found')
qtpy.PythonQtError: No Qt bindings could be found
When I try to install PySide, I get:
only these python versions are supported: [(2, 6), (2, 7), (3, 2), (3, 3), (3, 4)]
I currently use python3.5 for analysis and python2.7 for webdev.
So I uninstalled spyder using python3.5 -m pip uninstall spyder and try to install rodeo using pip as well as apt-get and neither work. I even tried sudo dpkg -i install rodeo.deb as explained here and got the following error:
dpkg: error processing archive install (--install):
cannot access archive: No such file or directory
dpkg: error processing archive rodeo.deb (--install):
cannot access archive: No such file or directory
Errors were encountered while processing:
install
rodeo.deb
Trying to download rodeo from their website at yhat.com loads a blank page with a single line Cannot GET /products/rodeo/downloads/linux64/null and nothing happens - no download.
How do I install & use either one of these IDEs or something that would generally make ML/DA work easier?
And I haven't played with alternate builds of python such as anaconda, jupyter, ipython, etc.
Thanks
Based on https://pythonhosted.org/spyder/installation.html#the-hard-way, the "No Qt bindings could be found" error for Spyder can be fixed by installing either PyQt5, which is recommended, or PyQt4 for Python 3. In Ubuntu, you can install PyQt5 by running:
sudo apt-get install python3-pyqt5
If you want to install PyQt4 instead, then run:
sudo apt-get install python3-pyqt4
I am using anaconda. Using pip gave this error. So i did following
pip uninstall spyder
conda install spyder
For installing Rodeo, the repo you're downloading is out of date. Try running the commands below to install the latest version. It should pickup your anaconda path automatically:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 33D40BC6
sudo add-apt-repository -u "deb http://rodeo-deb.yhat.com/ rodeo main"
#### install rodeo and run it
sudo apt-get -y install rodeo
/opt/Rodeo/rodeo

ImportError: cannot import name HTTPSHandler installing get-pip.py

I'm getting this error when I try to install pip2.7.
I have python 2.7 as my default already, but I'm not sure why I'm getting this.
OS: CentOS 6.5
OpenSSL has been installed already.
I followed this guide to install Python 2.7:
http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
[root#myservername arandomfolder]# python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 17474, in <module>
main()
File "get-pip.py", line 17466, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 17406, in bootstrap
import pip
File "/tmp/tmpXq2wUP/pip.zip/pip/__init__.py", line 10, in <module>
File "/tmp/tmpXq2wUP/pip.zip/pip/util.py", line 18, in <module>
File "/tmp/tmpXq2wUP/pip.zip/pip/_vendor/distlib/version.py", line 14, in <module>
File "/tmp/tmpXq2wUP/pip.zip/pip/_vendor/distlib/compat.py", line 31, in <module>
ImportError: cannot import name HTTPSHandler
You have a Python without SSL support compiled. Unfortunately, get-pip appears to require SSL support.
If you are using a Linux distribution, make sure OpenSSL is installed, including the headers when compiling Python from source.
So looks like i was missing the openssl-devel dependency
after I had installed that, i was able to install this.
I was having this issue on a Centos 6.5 machine even though I had openssl and openssl-devel installed. I was also using the steps from the site:
http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
I removed python packages I had installed before: virtualenv, NetworkX, and pil:
pip uninstall virtualenv
pip uninstall NetworkX
pip uninstall pil
Then I compiled Python 2.7 again and no longer had this issue. After I followed the steps in the link below, I reinstalled the above packages using pip2.7:
pip2.7 install virtualenv
pip2.7 install NetworkX
pip2.7 install pil --allow-external pil --allow-unverified pil
I have meet the same problem. I solved it by install openssl-devel and reconfigure, make, make install python3:
yum install openssl-devel
then go to the python3 directory:
./configure --with-zlib --with-openssl
make
make install

Categories