Jupyter cannot start, "ImportError: This package should not be accessible" - python

I am unable to start a Jupyter notebook server on a linux machine. When I type jupyter notebook, I get the following errors:
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
During handling of the above exception, another exception occurred:
ModuleNotFoundError: No module named 'urlparse'
Here is some system info, let me know if anything else might be helpful:
$ jupyter --version
4.4.0
$ which jupyter
/usr/bin/jupyter
$ which python
/usr/bin/python
$ which python3
/usr/bin/python3
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
$ cat /proc/version
Linux version 4.15.0-38-generic (buildd#lcy01-amd64-023) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #41-Ubuntu SMP Wed Oct 10 10:59:38 UTC 2018
$ pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/dist-packages (python 3.6)
When I try python2 -m pip install urlparse --user, I get an error: Collecting urlparse Could not find a version that satisfies the requirement
The reported error resembles the one shown here, but the stated solution of creating and using a python3 virtual environment doesn't seem to immediately fix the jupyter notebook command, although it does replace python and python3 executable with links to the virtual environment:
(env) $ which jupyter
/usr/bin/jupyter
(env) $ which python
/home/.../env/bin/python
(env) $ which python3
/home/.../env/bin/python3
In case there is some question about the python path, here is the path for python 2:
$ ipython
...
In [2]: sys.path
Out[2]:
['/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/$USER/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/home/$USER/.local/lib/python2.7/site-packages/IPython/extensions',
'/home/$USER/.ipython']
And for python3
$ ipython3
...
In [2]: sys.path
Out[2]:
['/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/$USER/.local/lib/python3.6/site-packages',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages',
'/home/$USER/.local/lib/python3.6/site-packages/IPython/extensions',
'/home/$USER/.ipython']
The full stack trace of the first error when starting Jupyter is:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/notebook/nbextensions.py", line 18, in <module>
from urllib.request import urlretrieve
File "/usr/lib/python3.6/urllib/request.py", line 88, in <module>
import http.client
File "/home/$USER/.local/lib/python3.6/site-packages/http/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
The contents of /usr/bin/jupyter are as follows:
$ cat `which jupyter`
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'jupyter-core==4.4.0','console_scripts','jupyter'
__requires__ = 'jupyter-core==4.4.0'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('jupyter-core==4.4.0', 'console_scripts', 'jupyter')()
)
One suggested answer is that there is a spurious http library, "it happens to be overridden by some 3rd-party module "http" at /home/$USER/.local/lib/python3.6/site-packages/http". When I remove this library manually, I now get an error importing the site module, as follows:
$ cd /home/$USER/.local/lib/python3.6/site-packages
$ mv ./http ~/Desktop/python_disabled/python3/
$ jupyter notebook
Error processing line 1 of /home/$USER/.local/lib/python3.6/site-packages/lazr.restfulclient-0.14.0-py3.6-nspkg.pth:
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.6/site.py", line 174, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/usr/lib/python3.6/types.py", line 171, in <module>
import functools as _functools
File "/usr/lib/python3.6/functools.py", line 21, in <module>
from collections import namedtuple
File "/usr/lib/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/home/$USER/.local/lib/python3.6/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.

This part is wrong:
File "/usr/lib/python3.6/urllib/request.py", line 88, in <module>
import http.client
File "/home/$USER/.local/lib/python3.6/site-packages/http/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
A standard module tries to import http.client, also a standard module. And in your installation, it happens to be overridden by some 3rd-party module "http" at /home/$USER/.local/lib/python3.6/site-packages/http.
Remove that 3rd-party module.
Judging by the same problem with reprlib package after uninstalling http in your updated question, you seem to have the micropython-lib set of packages installed in /home/$USER/.local/lib/python3.6. Since there are lots of them, it's easier to just delete the entire directory. I've no idea how they ended up there since they are not only incompatible with a regular CPython installation but with Python 3 in general.
Finally, note that depending on your needs, using virtualenv may be a more manageable solution than pip --user.

Related

How to import python3 lib in python3.6

I have virtual environment created for python 3.6. And I have install python3-pyqt5.qtwebkit package with apt-get. The package have installed in global python3.5 and its working, but if I try to import it from venv python3.6 there is import error... How can I install this package in my virtual environment? Or if this is not possible how can I use global package installed in 3.5 in my virtualenv 3.6 python.
Running with global python3.5
(virtualenv)
~/vcs-ss/sst master ✗ 5d ▴ ⚑ ✚ ◒
▶ python3.5 -c 'import PyQt5.QtWebKit; print(PyQt5.QtWebKit.__file__)'
/usr/lib/python3/dist-packages/PyQt5/QtWebKit.cpython-35m-x86_64-linux-gnu.so
Running with python3.6 from venv
(virtualenv)
~/vcs-ss/sst master ✗ 5d ▴ ⚑ ✚ ◒
▶ python3.6 test/e2e/browser.py
Traceback (most recent call last):
File "test/e2e/browser.py", line 8, in <module>
from PyQt5.QtWebKit import *
ModuleNotFoundError: No module named 'PyQt5.QtWebKit'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, 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 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "test/e2e/browser.py", line 8, in <module>
from PyQt5.QtWebKit import *
ModuleNotFoundError: No module named 'PyQt5.QtWebKit'
In order to use system packages inside a virtual environment, you have to use --system-site-packages option when creating virtual env:
virtualenv --python=python3.6 --system-site-packages env
The same switch is available in Python3's venv.
Much better option is (if applicable in your case) to install all packages inside your virtual env, using pip.
If you look at the contents of the package (using dpkg --listfiles python3-pyqt5.qtwebkit) you'll probably see something like this:
/.
/usr
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/PyQt5
/usr/lib/python3/dist-packages/PyQt5/QtWebKit.cpython-35m-x86_64-linux-gnu.so
/usr/lib/python3/dist-packages/PyQt5/QtWebKit.pyi
/usr/lib/python3/dist-packages/PyQt5/QtWebKitWidgets.cpython-35m-x86_64-linux-gnu.so
/usr/lib/python3/dist-packages/PyQt5/QtWebKitWidgets.pyi
/usr/share
/usr/share/doc
/usr/share/doc/python3-pyqt5.qtwebkit
/usr/share/doc/python3-pyqt5.qtwebkit/copyright
/usr/share/doc/python3-pyqt5.qtwebkit/changelog.Debian.gz
The package installs binary modules compiled for a specific python version (in this case: cpython-35m), you won't be able to use those from a python3.6 installation/venv directly because of the incompatible binary names.
For that to work you'd need to symlink all the .so files in the PyQt5 directory to your venv and there change cpython-35m-x86_64-linux-gnu to cpython-36m-x86_64-linux-gnu. Same for the sip libraries, as those are requiered by PyQt5. And that will only work if the ABI is compatible between the two versions.
A quick test with the versions mentioned above shows it works at least for simple scripts, but I can't give any guarantee.

Failed to start python after installing speech_recognition package

I've already installed this package (SpeechRecognition) on my laptop, now I'm trying to make it work on my Imac (sierra aswell).
I followed the installation the same as on the macbook.
But when trying to run the test I get following error.
python -m speech_recognition
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 163, in _run_module_as_main
mod_name, _Error)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 111, in _get_module_details
__import__(mod_name) # Do not catch exceptions initializing package
File "/usr/local/lib/python2.7/site-packages/speech_recognition/__init__.py", line 5, in <module>
import io
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Try going to terminal and typing in that:
python -m speech_recognition
or
python3 -m speech_recognition
If that's what your running.
it depends what version of python your using, Sierra comes with python IDLE 2.7.10 already installed.
if you download those modules for python it will download them to work with 2.7.10 not the 3.0 + you might be using.
so if you downloaded python3 and are trying to run it with python3 it won't work, only from 2.7.10 so try typing in.
python -m speech_recognition
Like i suggested and see if it works in the terminal, if it does then it means i was right and python 2.7.10 will work with it.

tox Invocation failed for Python 3

tox runs my Python 2.7 tests, but fails for Python 3.4. It gives an "Invocation failed" message. Excerpts:
py34 create: /home/josh/code/ezoutlet/.tox/py34
ERROR: invocation failed (exit code 1), logfile: /home/josh/code/ezoutlet/.tox/py34/log/py34-0.log
ERROR: actionid: py34
msg: getenv
cmdargs: ['/usr/bin/python', '-m', 'virtualenv', '--python', '/usr/bin/python3.4', 'py34']
And later
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Running virtualenv with interpreter /usr/bin/python3.4
ERROR: InvocationError: /usr/bin/python -m virtualenv --python /usr/bin/python3.4 py34 (see /home/josh/code/ezoutlet/.tox/py34/log/py34-0.log)
You need to look at the details of the error message. Notice the command that failed (from the first excerpt):
cmdargs: ['/usr/bin/python', '-m', 'virtualenv', '--python', '/usr/bin/python3.4', 'py34']
You can run this manually with:
/usr/bin/python -m virtualenv --python /usr/bin/python3.4 py34
Assuming you see the same error, your issue is with virtualenv rather than tox.
I reviewed the virtualenv help page and it seems like this should work. Faced with a possible bug, a good first step is to upgrade Python, virtualenv, or other libraries.
In my case, upgrading virtualenv was the solution:
pip install --upgrade virtualenv
Interestingly, this solution worked on both Windows and Linux. Most likely, there was a bug fix between when I got virtualenv and the latest release.

Passing Python3 to virtualenvwrapper throws up ImportError

I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.
This is sort of a workaround for now.
Create a virtualenv using pyvenv.
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,
pyvenv example ~/.virtualenvs/example
This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper
Hope this helps.
You can upgrade to the most recent version of virtualenv, with:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
The following command then works:
mkvirtualenv scriptcutter --python=/usr/bin/python3
Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of #pjotr_dolphin's comment, with the URL updated.

Error in installing SetupTools in Linux

So i trying install setuptools on a new server, so i got with
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
and trying to sh setuptools-0.6c11-py2.7.egg in the directory where the file is located and I get
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named setuptools.command.easy_install
I couldn't find any way of debugging this anywhere.
When I try
import sys
from setuptools.command.easy_install import bootstrap
sys.exit(bootstrap())
I get
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named setuptools.command.easy_install
When I enter sys.path in python interpreter it gives me the following:
['', '/opt/python2.7/lib/python27.zip', '/opt/python2.7/lib/python2.7', '/opt/python2.7/lib/python2.7/plat-linux3', '/opt/python2.7/lib/python2.7/lib-tk', '/opt/python2.7/lib/python2.7/lib-old', '/opt/python2.7/lib/python2.7/lib-dynload', '/opt/python2.7/lib/python2.7/site-packages']
You could try a few different things:
move the file to a different directory, cd to the same directory, and again try running sh setuptools-0.6c11-py2.7.egg.
Open the python2.7 interactive prompt (just run python2.7) in the same directory as where the file resides. Then run:
import sys
from setuptools.command.easy_install import bootstrap
sys.exit(bootstrap())
to attempt the installation manually
If that still doesn't work, run python2.7 and run the following python code, and add the information shown to your question:
import sys
import setuptools
print 'Path:', sys.path
print 'setuptools package:', setuptools.__file__
Last but not least, test that the downloaded egg was not somehow corrupted or truncated. Test for the md5 hash and size:
$ md5 setuptools-0.6c11-py2.7.egg
MD5 (setuptools-0.6c11-py2.7.egg) = fe1f997bc722265116870bc7919059ea
$ ls -l setuptools-0.6c11-py2.7.egg
-rw-r--r-- 1 own grp 332005 Jul 8 2010 setuptools-0.6c11-py2.7.egg
If they don't match, redownload the file and try again.

Categories