How to install gensim and run package in python? - python

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.)

Related

ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant'

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

what could be the reason for the importerror [duplicate]

This question already has answers here:
It Keeps showing this. What Should I do? [closed]
(2 answers)
Closed 2 years ago.
I am trying to train a model of CNN.
When I run the code, it returns following error:
Traceback (most recent call last):
File "train_network.py", line 5, in <module>
import matplotlib
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/matplotlib/__init__.py", line 138, in <module>
from . import cbook, rcsetup
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/matplotlib/cbook/__init__.py", line 32, in <module>
import numpy as np
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/numpy/core/__init__.py", line 102, in <module>
from . import _dtype_ctypes
File "/home/kaustubhj/.virtualenvs/dl4cv/lib/python3.7/site-packages/numpy/core/_dtype_ctypes.py", line 25, in <module>
import _ctypes
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
ImportError generally refers to an import library required for execution is not present within executing systems.
Few possible cases to look for.
In a general case, your system where py is running is missing this package.
In Spark(general-purpose computing cluster), if you are running this cnn then one of your worker node could be missing file/package.
Bugs: In Py bug tracker this bug reported for some package like Pipenv. This resolved as per https://bugs.python.org/issue40367 Just upgrade your used libs to stable version
If its path issue then check for which python you have installed library and which version you are using. I.e. there could be multiple python version in your systems. Python2 pkgs repo and Python3 pkgs repo loc are different.
If its simple OS path issue - https://jackiechen.org/2016/01/13/importerror-libffi-so-6-cannot-open-shared-object-file-no-such-file-or-directory/
Try to just use the latest version or switch to more stable version packages to avoid this error.

Can't import libpgm.graphskeleton, ModuleNotFoundError: No module named 'dictionary'

I need to build a Bayesian Network using naive bayes with libpgm.
The BN structure is known, so I just need to import it as a GraphSkeleton object with libpgm.graphskeleton.
When I run the code, it gives me the following error:
Traceback (most recent call last):
File "C:\Users\X\Documents\Modelli Probabilistici\0-NEW\reteBayesiana1.py", line 3, in <module>
from libpgm.graphskeleton import GraphSkeleton
File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\libpgm\graphskeleton.py", line 29, in <module>
from dictionary import Dictionary
<b>ModuleNotFoundError: No module named 'dictionary'</b>
I installed the library using "pip3 install libpgm" and I didn't get any errors during the installation.
Here is my Code:
import libpgm
from libpgm.graphskeleton import GraphSkeleton
skel = GraphSkeleton()
skel.load("skeleton.txt")
...
I checked my libraries folder and libpgm seems to be installed correctly, also there are both a 'graphskeleton.py' file and a 'dictionary.py' file and they both seem to have the objects needed (GraphSkeleton and Dictionary, which is required for 'graphskeleton.py')

Exception during calling gensim?

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

importing module in Spyder error

I am trying to use sklearn in Spyder. At the beginning when I tried to import it I was gettingImportError: No module named sklearn
Then I tied to set the PATH with PYTHONPATH manager and then use 'Update module names list' from tools menu.then restart the spydet but no success.
at the end I copied the sklearn folder to /Applications/Spyder.app/Contents/Resources/lib/python2.7
This is how I find the PATH of sklearn and copied in into this folder :
>>> import sklearn
>>> sklearn
<module 'sklearn' from '/Library/Python/2.7/site-packages/scikit_learn-0.12_git-py2.7-macosx-10.7-intel.egg/sklearn/__init__.pyc'>
>>>
and then I cd to the parent folder :
cp -r sklearn /Applications/Spyder.app/Contents/Resources/lib/python2.7
but when I try to import the sklearn to spyder like from sklearn import dataset :
Traceback (most recent call last):
File "/Users/mohsenjadidi/Documents/workspace/dsv/test.py", line 10, in <module>
from sklearn import dataset
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/__init__.py", line 17, in <module>
from .base import clone
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/base.py", line 11, in <module>
from .metrics import r2_score
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/metrics/__init__.py", line 6, in <module>
from .metrics import confusion_matrix, roc_curve, auc, precision_score, \
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/metrics/metrics.py", line 17, in <module>
from ..utils import check_arrays
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/utils/__init__.py", line 9, in <module>
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 151, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:4773)
ValueError: numpy.dtype has the wrong size, try recompiling
any idea?Thanks
Moj, Spyder MacOS X App uses its own (internal) Python interpreter, not the system one. This was the only way we (the devs) found to provide a self contained app with numpy, scipy, matplotlib and IPython, without messing with system Python.
Right now I think there is no way to add more packages to the app, but we'll try to improve the situation during the next couple of months.
The other alternative (the one we envisaged) is for users who want more packages to download and install latest EPD and change their Python interpreter in
Tools > Preferences > Console > Advanced Settings > Python Executable
I faced the same problem importing networkx. Drag-drop its folder into spyder's folder was enough for me.

Categories