ImportError: cannot import name _NONE - python

For some reason I'm getting this error when trying to import gevent inside my docker container:
# python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gevent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gevent/__init__.py", line 51, in <module>
from gevent.hub import get_hub, iwait, wait
File "/usr/local/lib/python2.7/dist-packages/gevent/hub.py", line 31, in <module>
from gevent._util import _NONE
ImportError: cannot import name _NONE
>>>
Which is odd because _util.py exists, it's in the dist-packages/gevent directory. When I did a pip install on another system, it works fine.
Anyone have any ideas what might be going on?

Have you upgraded gevent package recently or maybe installed it over old version?
I ran pip install --ignore-installed gevent to update old version of this package in my virtualenv, and then this error starts to appear.
I fixed it with pip uninstall gevent (two times to completely remove it) followed by pip install gevent.

I think you import gevnet this module is not you see it.
you can print something in you _util.py module.
if nothing print, I guess "/usr/local/lib/python2.7/dist-packages/gevent/hub.py" import _util is not in /usr/local/lib/python2.7/dist-packages/gevnet, and you can try to print sys.path to find real import path and fix it.
In my Method:
uninstall gevent.
use a another system gevnet or virtualenv package,and copy to you real(I guess you have a env path like '/usr/local/lib64')
exec python -c 'import gevent' test is ok.

Related

ImportError: cannot import name for Python package

I am using Python 3.6 and I have a strange import error. My Python file contains only the line import formic. But when I execute the script, I get the following error:
from formic import FileSet, Pattern, get_version
ImportError: cannot import name 'FileSet'
I have tried installing Formic both with and without sudo (yes, I know that I shouldn't use pip with sudo, but sometimes you get desperate)
I have used Formic before, but can't figure out what is going on in this situation.
If I only have import sys, then the script runs just fine with no errors, as expected.
Any ideas why this error occurs? Or how to fix it?
Additional Information
I don't have a circular dependency, because Formic is a Python package
https://stackoverflow.com/a/9252628/623541
I have deleted the __pycache__ folder
https://stackoverflow.com/a/73954626/623541
I have tried fixing PYTHONPATH
https://stackoverflow.com/a/15052360/623541
export PYTHONPATH=/home/myName/Workspace/myProject/.pyenv/lib/python3.6/site-packages
I have tried installing with sudo -H
https://stackoverflow.com/a/52159621/623541
I have tried installing Formic with --no-cache-dir
https://stackoverflow.com/a/9510610/623541
I have purged cache with pip cache purge
I have tried fixing permissions in the site-packages directory.
https://stackoverflow.com/a/16377297/623541
I have verified that Formic is installed:
$ /home/myName/Workspace/myProject/.pyenv/bin/pip3 show formic
Name: formic
Version: 0.9b8
Summary: An implementation of Apache Ant FileSet and Globs
Home-page: http://www.aviser.asia/formic
Author: Aviser LLP, Singapore
Author-email: formic#aviser.asia
License: GPLv3+
Location: /home/myName/Workspace/myProject/.pyenv/lib/python3.6/site-packages
Requires:
Required-by:
But if I try to import Formic from the same Python, it fails:
$ /home/myName/Workspace/myProject/.pyenv/bin/python
Python 3.6.9 (default, Jun 29 2022, 11:45:57)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import formic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/myName/Workspace/myProject/.pyenv/lib/python3.6/site-packages/formic/__init__.py", line 27, in <module>
from formic import FileSet, Pattern, get_version
ImportError: cannot import name 'FileSet'
The only solution I found was to upgrade to Formic2 and update the code to support it.

Python 3: ModuleNotFoundError: No module named 'pandas.util' (raspberry pi)

Am having issues importing pandas on python3 on my raspberry pi. Whatever I try, I get the following error:
pi#raspberrypi:/ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/__init__.py", line 15, in <module>
from pandas.compat.numpy import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/numpy/__init__.py", line 7, in <module>
from pandas.util.version import Version
ModuleNotFoundError: No module named 'pandas.util'
It works fine on Python 2.7. I am getting errors with Python 3.7.3.
I searched Google and tried everything in the following post:
ImportError: No module named pandas
Some of the things I’ve tried are below - none have helped - I still get the error.
pip3 install pandas-util
pip3 install pandas.util
sudo apt-get install python3-wheel
sudo python3 -m pip install pandas
pip3 install pandas --upgrade
I've also tried uninstalling and reinstalling numpy and pandas - still get this error just with a basic import statement.
Any help would be appreciated as this is driving me insane!!
Cheers!
Try with
python3 -m pip install --force-reinstall pandas
This will ensure two things:
it will use the pip executable that belongs to the used Python executable, so that there is no accidental installation by another pip.
it will properly re-install Pandas.
Note that it doesn't re-download the Pandas package (it will use a cached version) if the version on PyPI hasn't changed between now and the previous installation. If that is a potential problem (incorrect cached file, for example), add the option --no-cache-dir to pip install.

Python 3.7 import requests returns "Chardet" error

When importing requests in python3, I'm getting the following error:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32
bit (Intel)] on win32 Type "help", "copyright", "credits" or
"license" for more information
>>>> import requests
Traceback (most recent call last): File "<stdin>", line 1, in <module> File
"C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests-2.19.1-py3.7.egg\requests\__init__.py", line 44, in <module>
import chardet
ModuleNotFoundError: No module named 'chardet'
This is a fresh install, but because of the env I'm working in, I couldn't use pip to install requests. I had to download the source and install via the setup.py install file.
Doing some searches yields some results, but nothing that seems to be a solution for my situation.
Thanks
It is a dependency and is missing from you site-packages. Since you said you can't use pip you have to install the dependencies manually.
requires = [
'chardet>=3.0.2,<3.1.0',
'idna>=2.5,<2.8',
'urllib3>=1.21.1,<1.24',
'certifi>=2017.4.17'
]
this is what requests setup files mentioned as requirements for requests. Try installing all of these and try again.
hope this helps!
Try installing chardet module using this command:
pip3 install chardet

Can't import pyttsx in Python 2.7 on Ubuntu Linux 16

I'm trying to use pyttsx on Ubuntu Linux (64 bit, PC) with Python 2.7. I've successfully used pip to install the package
$sudo -H pip install pyttsx
$pip list
...
pyttsx (1.1)
...
When I try to import it the import call fails
$ python
Python 2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyttsx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pyttsx
I'm not sure why I'm getting this. When I search for the question here on Stack Overflow I encounter one other instance about the same error message on a Raspberry Pi. But the solution mentioned there doesn't bring resolution on my PC so I don't think it is not related.
Any ideal what I am missing that is preventing the import from being successful?
Make sure your pip is tied to your python installation by checking both path's.
In Pip check:
`pip --version`
pip 9.0.1 from C:\Python27\lib\site-packages (python 2.7)
Later in python:
import sys
print sys.executable
C:\Python27\python.exe
run which pip, which python, make sure they are same suite
when run pip install, it should feedback the package is installed in which path
run this code in python
import sys
for i in sys.path:
print i
to check if your syspath including that path or not.

ImportError: No module named 'paramiko'

I have done through the other questions online here, and I feel that mine is different enough to warrant a new question.
So I have a Centos 6 box, which is running a small website for me, acts as an office git server and I am trying to configure Python3 on it.
So I followed the following these steps to set up python3 on the server. However it seems that I cannot import paramiko into my script.
I downloaded the paramiko rpm however I get this message:
When I try to import paramiko I get:
[root#GIT Python-3.4.2]# rpm -ivh /usr/lib/Python-3.4.2/Modules/python-paramiko-1.7.5-2.1.el6.noarch.rpm
Preparing... ########################################### [100%]
package python-paramiko-1.7.5-2.1.el6.noarch is already installed
When I run python3 directly:
[root#GIT inserv_health_check]# python3
Python 3.4.2 (default, Jan 21 2015, 06:28:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paramiko
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'paramiko'
>>>
I am sure there is a simple solution to this problem perhaps the path is wrong, or I should have put a symbolic link in somewhere. Any help would be appreciated :)
Before anyone asks, which python output:
[root#GIT Python-3.4.2]# which python
/usr/bin/python
[root#GIT Python-3.4.2]# which pytho~n3
/usr/bin/which: no pytho~n3 in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root#GIT Python-3.4.2]# which python3
/usr/local/bin/python3
Thanks
You need to do pip install paramiko so that python sees that module. If you work on a virtual environment, you need to workon <env_name> first and then pip install the desired module.
type pip3 install paramiko
if you want to install it for python3

Categories