I tried to load gensim in my code. Often it works fine. Today, I get the following exception:
Traceback (most recent call last):
File "/project/6008168/tamouze/just.py", line 2, in <module>
import gensim
File "/project/6008168/tamouze/Python_directory/ENV2.7_new/lib/python2.7/site-packages/gensim/__init__.py", line 5, in <module>
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "/project/6008168/tamouze/Python_directory/ENV2.7_new/lib/python2.7/site-packages/gensim/parsing/__init__.py", line 4, in <module>
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "/project/6008168/tamouze/Python_directory/ENV2.7_new/lib/python2.7/site-packages/gensim/parsing/preprocessing.py", line 40, in <module>
from gensim import utils
File "/project/6008168/tamouze/Python_directory/ENV2.7_new/lib/python2.7/site-packages/gensim/utils.py", line 44, in <module>
from smart_open import smart_open
File "/project/6008168/tamouze/Python_directory/ENV2.7_new/lib/python2.7/site-packages/smart_open/__init__.py", line 1, in <module>
from .smart_open_lib import *
File "/project/6008168/tamouze/Python_directory/ENV2.7_new/lib/python2.7/site-packages/smart_open/smart_open_lib.py", line 29, in <module>
import requests
File "/project/6008168/tamouze/Python_directory/ENV2.7_new/lib/python2.7/site-packages/requests/__init__.py", line 97, in <module>
from . import utils
File "/project/6008168/tamouze/Python_directory/ENV2.7_new/lib/python2.7/site-packages/requests/utils.py", line 26, in <module>
from ._internal_utils import to_native_string
ImportError: cannot import name to_native_string
Im using python 2.7.14 and gensim 3.4.0.
How can I solve this problem?
The error isn't really occurring in gensim, even though that's how you found it. If you look at the stack, it's only triggered because gensim uses smart_open which in turn uses requests. It is in requests that the error happens.
If this was working, but now stopped, something likely changed in your environment, or how you're launching this code, related to the relationship between Python and the requests package.
For such errors, you should try searching Google for the final-two lines of your error stack – those most connected to the problem. Those are:
from ._internal_utils import to_native_string
ImportError: cannot import name to_native_string
(These leave out the file path that's specific to you, but have a number of unique tokens likely to have also been reported by any others.)
A number of people have hit this, from a variety of other projects, but always triggered through requests. Some have reported re-installing requests (perhaps to ensure it's version 2.0.0 or later) helps.
If a simple re-install doesn't help, you could also try one or all of:
uninstall, verify it's not present at all (that requests itself isn't found), then install – this could make sure you don't have overlapping redundant installations in different places that are both confusing the issue
start from a fresh Python environment, reinstalling all packages
double-check that all packages share the same Python2/Python3 compatibility
Related
Traceback (most recent call last):
File "g:\mydrive\ \pdftotext_pdfminer.py", line 3, in <module>
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\pdfinterp.py", line 7, in <module>
from .cmapdb import CMap
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\encodingdb.py", line 7, in <module>
from .psparser import PSLiteral
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\psparser.py", line 22, in <module>
from .utils import choplist
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\utils.py", line 31, in <module>
import charset_normalizer # For str encoding detection
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\__init__.py", line 23, in <module>
from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\api.py", line 10, in <module>
from charset_normalizer.md import mess_ratio
File "charset_normalizer\md.py", line 5, in <module>
ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' (C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\constant.py)
This error happens whenever I'm using pdfminer. I also installed pdfminer-six
My code worked just fine until two days ago.
It started to happen today when I tried to just run it again without any adjustment in the file
I'm assuming maybe it's the pdfminer's problem but there's no update about the module...
(I'm running this on my conda env)
Does anyone know what this error means? and how to fix it?
When I encountered this I used:
pip install chardet
there. I faced the same problem when trying to use the pdfplumber package today (2022-11-24) from a script I have long used with no problem. I don't know why this error is happening but found one of the solutions in this link helpful:
How to fix AttributeError: partially initialized module?
Briefly, I removed my entire virtual environment using the command conda env remove --name ds (being ds the name of my environment). Then, I created a new one and installed every package I needed again through conda or pip. It is working perfectly now. Hope it works for you as well.
Out of curiosity, I have installed Tensorflow last week. Maybe it interfered with pdfplumber somehow (not sure). Have you installed any new package since the last time you used pdfminer? Best of luck!
use follow instead.
pip install mmcv-full==1.3.17
i want to do in python 3.7.4:
and getting this Error:
i already tried:
using conda and pip
using local windows and windows server
multiple reinstallments of diffenent versions of packages (e.g. numpy and scipy)
from gensim.models import Word2Vec
Traceback (most recent call last):
File "c:/Users/Administrator/Documents/GitHub/contract-criteria-identifier-on-aws/schnelltest.py", line 1, in
import gensim
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\gensim__init__.py", line 5, in
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\gensim\parsing__init__.py", line 4, in
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\gensim\parsing\preprocessing.py", line 42, in
from gensim import utils
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\gensim\utils.py", line 40, in
import scipy.sparse
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\sparse__init__.py", line 230, in
from .csr import *
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\sparse\csr.py", line 13, in
from ._sparsetools import (csr_tocsc, csr_tobsr, csr_count_blocks,
ImportError: DLL load failed: The specified module could not be found.
PS C:\Users\Administrator\Documents\GitHub\contract-criteria-identifier-on-aws> & C:/Users/Administrator/AppData/Local/Programs/Python/Python37/python.exe c:/Users/Administrator/Documents/GitHub/contract-criteria-identifier-on-aws/schnelltest.py
Traceback (most recent call last):
File "c:/Users/Administrator/Documents/GitHub/contract-criteria-identifier-on-aws/schnelltest.py", line 1, in
import gensim
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\gensim__init__.py", line 5, in
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\gensim\parsing__init__.py", line 4, in
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\gensim\parsing\preprocessing.py", line 42, in
from gensim import utils
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\gensim\utils.py", line 40, in
import scipy.sparse
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\sparse__init__.py", line 230, in
from .csr import *
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\sparse\csr.py", line 13, in
from ._sparsetools import (csr_tocsc, csr_tobsr, csr_count_blocks,
ImportError: DLL load failed: The specified module could not be found.
That error is actually suggesting some problem in scipy's installation – that's the source of the actual line of code where the DLL load failed error arises. You should try:
(1) uninstalling & reinstalling conda
(2) ensuring you've activated a "conda environment"
(3) manually conda-installing individually required packages, like scipy, and watching the output carefully for any warnings/errors
(4) when finally running your code, still ensuring you've activated the right conda environment
If you still have problems, expand your question with more specific details about how each part was installed, and whether there was reported success or failure at each step.
Notably, conda is usually very helpful in getting these packages working under Windows. But in general, they all get the most development, use, and quality-attention under more Unix/Linux-like systems. So if you have the option to not use Windows, everything may have a better chance of working, and when you hit problems, you'll have a larger body of prior docs/help to draw upon. (It all can still be made to work on Windows, but often requires using secondary or less-preferred installation/configuration options.)
I try to import discord in python 3.5, but I get the following traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python\Python35-32\lib\site-packages\discord\__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "C:\Python\Python35-32\lib\site- packages\discord\client.py", line 42, in <module>
from .voice_client import VoiceClient
File "C:\Python\Python35-32\lib\site- packages\discord\voice_client.py", line 65, in <module>
from .gateway import *
File "C:\Python\Python35-32\lib\site- packages\discord\gateway.py", line 31, in <module>
import aiohttp
File "C:\Python\Python35-32\lib\site- packages\aiohttp\__init__.py", line 10, in <module>
from .protocol import * # noqa
File "C:\Python\Python35-32\lib\site- packages\aiohttp\protocol.py", line 11, in <module>
from wsgiref.handlers import format_date_time
ImportError: cannot import name 'format_date_time'
I installed discord inside Python35-32\Scripts using pip install discord. Additionally, I installed asyncio using pip install asyncio in the same directory.
The error pops up in my command prompt, when I type in "python", wait for it to open, and then type "import discord". I'm saying that just to be clear that it's not a "I have a file named XXX.py which clashes with something from the discord library" type of error.
Based on the comments you have added and the line
File "C:\Python\Python35-32\lib\site- packages\aiohttp\protocol.py", line 11, in <module>
from wsgiref.handlers import format_date_time
ImportError: cannot import name 'format_date_time'
The problem seems to be that 'format_date_time' could not be imported from the built in library wsgiref. Turns out that the file ...\Python35-32\lib\wsgiref\handlers.py was completely empty indicating that something corrupted your python installation.
Two possible solutions:
Reinstall your python completely which also has the benefit of solving other potential corruptions that you might not have noticed yet (Note that the underlying cause for this corruption remains unknown)
Go into the Cython git and copy the contents of the handlers.py into the local file. This is a very specific solution however and you should be aware that other parts of your python installation might also be corrupt.
Maybe you wanted to pip install discord.py instead of discord?
I have a cloud instance of a Linux machine (openSuSE) with multiple users.
I have created a virtual environment and installed all my required libraries (including Klein).
I have two users "a" and "b".
While logged in as "a" and inside virtualenv, when I open python shell at home directory and type
import klein
it imports normally.
Now when I change directory to
/home/b/
and run the same (open python shell, import klein) while being in the same virtualenv, it gives me an error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/a/.local/lib/python3.6/site-packages/klein/__init__.py", line 3, in <module>
from klein._plating import Plating
File "/home/a/.local/lib/python3.6/site-packages/klein/_plating.py", line 16, in <module>
from .app import _call
File "/home/a/.local/lib/python3.6/site-packages/klein/app.py", line 19, in <module>
from twisted.internet import endpoints, reactor
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/endpoints.py", line 58, in <module>
from twisted.protocols.tls import TLSMemoryBIOFactory
File "/home/a/.local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 63, in <module>
from twisted.internet._sslverify import _setAcceptableProtocols
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 158, in <module>
verifyHostname, VerificationError = _selectVerifyImplementation()
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 141, in _selectVerifyImplementation
from service_identity import VerificationError
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/__init__.py", line 7, in <module>
from . import cryptography, pyopenssl
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/cryptography.py", line 16, in <module>
from .exceptions import SubjectAltNameWarning
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/exceptions.py", line 21, in <module>
#attr.s
AttributeError: module 'attr' has no attribute 's'
Command "which python" gives same address at both location which is my virtualenv python address and that should be expected.
But what causes this weird python shell behavior.
Thank you
I solved it and a very shameful reason caused the error.
One of the modules Twisted uses is "attr" module. I had named one of my files attr.py and that is what was causing all the error.
I myself am not deleting this question if moderation has no problem, maybe somebody like me might be stuck at the same situation. It may help them.
Never name your python files same as that of any standard module unless overriding.
Also if your issue persists, then Jean's answer will definitely resolve it.
There can be multiple different Python packages that provide the same Python module. For example, there are at least two packages that provide the attr module:
https://pypi.org/project/attr/
https://pypi.org/project/attrs/
It's possible you've installed the wrong package based on the requirements. You can check what you have installed with pip freeze.
I want to use matplotlib in my Google App Engine project. I followed the steps, described here in the official docs. What I did:
1) Created a directory named lib in my application root directory.
2) Created a file appengine_config.py in my application root directory and added there these lines:
from google.appengine.ext import vendor
vendor.add('lib')
3) Since the docs say, that the only version of matplotlib working is 1.2.0, I executed the following command in the Terminal:
pip install -t lib matplotlib==1.2.0
There is also step 0 in the docs, which says
Use pip to install the library and the vendor module to enable importing packages from the third-party library directory.
But I don't understand what it actually means. If this is something essential, please, explain to me what it's meant here. I found this answer here on stackoverflow, and It seems there is nothing different from what I have done.
Also, I added
libraries:
- name: matplotlib
version: "1.2.0"
to app.yaml.
So, after all these steps I add the line
import matplotlib
to main.py and start a local server with
python ~/path/google_appengine/dev_appserver.py app.yaml
But when I try to access http://localhost:8080/, the error is raised:
raise ImportError('No module named %s' % fullname)
ImportError: No module named _ctypes
The whole output, if needed, looks like this:
ERROR 2016-08-11 16:26:51,621 wsgi.py:263]
Traceback (most recent call last):
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/home/magnitofon/realec-inspector/main.py", line 20, in <module>
import matplotlib
File "/home/magnitofon/realec-inspector/lib/matplotlib/__init__.py", line 151, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/home/magnitofon/realec-inspector/lib/matplotlib/rcsetup.py", line 20, in <module>
from matplotlib.colors import is_color_like
File "/home/magnitofon/realec-inspector/lib/matplotlib/colors.py", line 52, in <module>
import numpy as np
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 705, in load_module
module = self._find_and_load_module(fullname, fullname, [module_path])
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 446, in _find_and_load_module
return imp.load_module(fullname, source_file, path_name, description)
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 22, in <module>
from . import _internal # for freeze programs
File "/usr/local/lib/python2.7/dist-packages/numpy/core/_internal.py", line 14, in <module>
import ctypes
File "/usr/lib/python2.7/ctypes/__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 963, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named _ctypes
What am I doing wrong?
matplotlib is one of the Google-provided 3rd party libs, so you should be following just the Requesting a library instructions and
not the Installing a library ones.
Sadly they're now both on the same documentation page, called Using Built-in Libraries in Python 2.7 - very confusing for the unaware as the vendoring technique should be used for libraries which are not GAE built-in/provided. Filed Issue 13202.
Note: pay attention to the Using libraries with the local development server section, it applies to matplotlib. You may need to install some packages on your system, but not in the application itself (which could negatively affect your deployment on GAE) - they need to be accessible by the development server, not directly by your application.
Duh, I just noticed the Using matplotlib section, on the same page :)
It mentions:
Note: The experimental release of matplotlib is not supported on the development server. You can still add matplotlib to the
libraries list, but it will raise an ImportError exception when
imported.
Some searching into this issue surfaced this (old) recipe:
http://code.activestate.com/recipes/578393-gae-matplotlib-demo/
be sure to read the comments.
However I tried, I was not able to make it work. It be this approach just does not work with the current version of the app engine sandbox anymore, or I just was not able to follow all the steps in the recipe correctly.
Maybe an even better read are the comments of Matt Giuca (a google engineer who ported matplotlib to work in GAE production env.) and his pull request in github.
https://github.com/matplotlib/matplotlib/issues/1823/
His comment of April 17, 2013 gives a recipe for matching the dev_appserver (version 1.77) to work with the matplotlib locally.
Maybe this helps someone dealing with this issue.