I'm learning Python at the moment, and after installing the docx module, I keep getting this error when trying to import it in the Terminal:
import docx
Traceback (most recent call last):
File "", line 1, in
File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/init.py", line 14, in
from docx.parts.document import DocumentPart
File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/parts/document.py", line 7, in
from docx.document import Document
File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/document.py", line 10, in
from docx.section import Section, Sections
File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/section.py", line 7, in
from collections import Sequence
ImportError: cannot import name 'Sequence' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/init.py)
When trying to import it to my Mu Editor, I get this error:
import docx
~/Library/Application Support/mu/mu_venv-38-20211212-105811/lib/python3.8/site-packages/docx.py in
28 TAGS = {}
29
---> 30 from exceptions import PendingDeprecationWarning
31 from warnings import warn
32
ModuleNotFoundError: No module named 'exceptions'
Can someone please help me figure out how to fix this problem? Thanks.
I have readed on internet and a solution may be:
$ pip install python-docx
#instead of pip install docx
(for python 3.x)
Please try this and tell me if works
Link: https://flutterq.com/solved-import-no-module-named-exceptions/
Are you using the most recent version of python-docx? (currently 0.8.11). I found that when I used 0.8.10 python couldn't find all the modules.
You can use where python command in cmd to find the path that python is installed in. then you can use this command -
[python path] -m pip install python-docx
$ pip install python-docx
this worked for me.
I've installed the pptx package using the following command:
pip install python-pptx
However, When ever I try to import the package this is the output I receive:
Traceback (most recent call last):
File "/Users/divyabahri/Documents/hello.py", line 5, in <module>
import pptx
ModuleNotFoundError: No module named 'pptx
Can someone please guide me regarding the latter issues, Thanks in Advance!
Mismatch in the python version could be the cause of the error. The problem can be fixed by explicitly using PIP version 3 and also Python version 3.
Working demo:
Step 1: Install python-pptx and its dependencies using pip version 3
$ pip3 install python-pptx
$ pip3 install lxml ---> dependency
$ pip3 install pillow ---> dependency
Step 2: Python 3 program to create a pptx file
# File name: demo.py
from pptx import Presentation
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
prs.save('test.pptx')
Step 3: Execute the program using Python version 3
$ python3 demo.py
Step 4: Verify that the test.pptx file got created.
There can be many reasons for that:
1.- Python pptx only supports python version 3.6 or less here is the documentation https://python-pptx.readthedocs.io/en/latest/user/install.html
2.- Check also your path, check if python version that is availabel for pptx is on the path, here you can see how to check your path, https://winaero.com/blog/how-to-see-names-and-values-of-environment-variables-in-windows-10/
3.- pip is outdated, try to upgrade your pip
4.- maybe you import bad the library, here you can see how to import it, https://python-pptx.readthedocs.io/en/latest/user/quickstart.html
I am trying to run a python script from python script.
I tried to run it like this:
os.system("python /opt/mycroft/skills/useridentification-skill/speakerIdentificationProgram/scoring.py")
Then I tried to import the file like this:
import sys
sys.path.append("/opt/mycroft/skills/useridentification-skill/speakerIdentificationProgram")
from scoring import get_id_result
they both returned this error:
File "/opt/mycroft/skills/useridentification-skill/__init__.py", line 9, in <module>
from scoring import get_id_result
File "/opt/mycroft/skills/useridentification-skill/speakerIdentificationProgram/scoring.py", line 2, in <module>
import numpy
ImportError: No module named 'numpy'
just try pip install numpy in your terminal. this will remove error
I think you are using numpy module in scoring.py but you have not installed numpy in your virtual environment.
Use "pip install numpy" after activating your virtualenv.
I assume you followed this to add skills, if so it should install numpy if the skill actually required it
https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/msm
Ref - https://github.com/MycroftAI/documentation/issues/143
Otherwise, you should be using
mycroft-pip install numpy
And you should be source to activate the mycroft venv, and then use the Python command to run your script
Use Panda libraries for data manipulation and file access.
https://www.learnpython.org/en/Pandas_Basics
I haven't used RPy2 for a number of years (and then I only played around a bit). However, I now want to start using Python and R a bit more seriously and decided to re-explore the RPy2 library.
I'm using a Mac running El Capitan. I created a new virtual environment (called env34) using Python 3.4.4 and installed the latest version of pip (19.1.1) using get-pip.py. I then pip installed numpy, pandas and jupyter into the activated environment. I also pip installed RPy2 (but had to include a trusted-host flag):
(env34) $ pip install rpy2 --trusted-host=https://pypi.org/simple/cffi
I also installed the latest version of R (3.6.0) in the default location in Applications folder and edited .bash_profile to create a RHOME environment variable by adding the following:
RHOME="/Library/Frameworks/R.framework/Resources"
export RHOME
Now when I launch Python in the virtual environment, I can import rpy2 with no problems. However, I'm trying to follow the tutorial given at http://heather.cs.ucdavis.edu/~matloff/rpy2.html and when I try to import rpy2.robjects using:
>>> from rpy2.robjects import r
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/path_to_virtual_environment/env34/lib/python3.4/site-packages/rpy2/robjects/__init__.py", line 14, in <module>
import rpy2.rinterface as rinterface
File "/path_to_virtual_environment/env34/lib/python3.4/site-packages/rpy2/rinterface.py", line 5, in <module>
import rpy2.rinterface_lib._rinterface_capi as _rinterface
File "/path_to_virtual_environment/env34/lib/python3.4/site-packages/rpy2/rinterface_lib/_rinterface_capi.py", line 8, in <module>
from . import conversion
File "/path_to_virtual_environment/env34/lib/python3.4/site-packages/rpy2/rinterface_lib/conversion.py", line 8, in <module>
from . import _rinterface_capi as _rinterface
ImportError: cannot import name '_rinterface_capi'
As far as I can see, all the files referenced in the message exist in the correct locations.
Can anyone interpret this error message and perhaps offer a workaround?
Thanks in advance.
Initially I was getting this error (No Module name was found scipy) So I installed a Scipy wheel file. Now I don't get the same error any more but I get cannot import name "_ccallback_c".
The error seems to be triggered at the fourth line of code. I have done my research and saw that other people suggested to try an environment such as Anaconda. I have seen it work on idle, and that solution isn't ideal for me.
Traceback:
Traceback (most recent call last):
File "C:\Users\joesh\Desktop\Python\Machine Learning\1st tutorial.py", line 4, in <module>
from sklearn import preprocessing, cross_validation, svm
File "C:\Users\joesh\Desktop\Python\lib\site-packages\sklearn\__init__.py", line 134, in <module>
from .base import clone
File "C:\Users\joesh\Desktop\Python\lib\site-packages\sklearn\base.py", line 10, in <module>
from scipy import sparse
File "C:\Users\joesh\Desktop\Python\lib\site-packages\scipy\__init__.py", line 118, in <module>
from scipy._lib._ccallback import LowLevelCallable
File "C:\Users\joesh\Desktop\Python\lib\site-packages\scipy\_lib\_ccallback.py", line 1, in <module>
from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'
And the code:
import pandas as pd
import quandl, math
import numpy as np
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
I had the same error on USING Anaconda, so I am not sure if using it would make any difference.
I solved it by just uninstalling scipy and re-installing it using pip:
pip uninstall scipy
you'll get this message:
Uninstalling scipy-1.1.0: Would remove:
c:\users\thesh\appdata\local\programs\python\python36-32\lib\site-packages\scipy-1.1.0.dist-info*
c:\users\thesh\appdata\local\programs\python\python36-32\lib\site-packages\scipy*
Proceed (y/n)?
press y, and after pip is done, type:
pip install scipy
Having just moved to MSVS 2017 for Python (ML) development, I encountered this and other errors related to missing modules. The problem (and all related problems like it) has a frustratingly simple solution: when I originally started coding in Python, I installed everything from the command line - apparently, MSVS 2017 doesn't "see" those installations (and, in fact, they sometimes conflict, since the underlying python may be tapping older libs); so, the solution is to:
Use the command line version of 'pip uninstall ...' where '...' is the library having missing dependencies (scipy, in this case). Then, in the MSVS 2017 command line on the Python environment window (usually, top right in the default display configuration), reload the library (in this case, typing 'scipy' will format a command line for execution [in the list control below the command textbox]) that will read something like 'pip install scipy' (or whatever library needs to be reinstalled for MSVS).
You may have to do this for many (or all) of your previous Python package installations where these missing module errors persist.
Can be resolved, by uninstalling and reinstalling using pip on Anaconda Prompt:
pip uninstall scipy
After the uninstall, you can reinstall with:
pip install scipy
When you installed scipy with pip in a Python version 3.6 and later try to run your code with Python 3.7 you will encounter this problem. So one solution is to uninstall scipy
pip3 uninstall scipy
and reinstall it (using an environment with Python 3.7):
pip3 install scipy
This will make sure that the installed version of scipy is compatible with your version of Python.
PS: When you updated Python from Python 3.6 to Python 3.7 it might be necessary to also reinstall pip, so that pip will use the correct version of Python internally.
I ran into this when I was following these instructions on how to use a virtual environment to use the pre-built version of SciPy. The simplest solution for me was to simply comment out from . import _ccallback_c under scipy\_lib\_ccallback.py.
I first had the error with scipy. So I ran the command python -m pip install -user numpy scipy matplotlib ipython jupyter pandas sympy noseand it worked perfectly. I was installing everything with pip, so I decided to use Anaconda. I installed and checked to add to the PATH. From there, the same code that was executed before normally stopped working and displays the error similar to that of the question. I uninstalled Anaconda and it is now working again.
Erro:
$ winpty python ia.py
Traceback (most recent call last):
File "ia.py", line 11, in <module>
from sklearn import tree #importando a biblioteca e a árvore p/ o classifica
dor
File "C:\Users\ferna\Anaconda3\lib\site-packages\sklearn\__init__.py", line 13
4, in <module>
from .base import clone
File "C:\Users\ferna\Anaconda3\lib\site-packages\sklearn\base.py", line 11, in
<module>
from scipy import sparse
File "C:\Users\ferna\AppData\Roaming\Python\Python36\site-packages\scipy\__ini
t__.py", line 118, in <module>
from scipy._lib._ccallback import LowLevelCallable
File "C:\Users\ferna\AppData\Roaming\Python\Python36\site-packages\scipy\_lib\
_ccallback.py", line 1, in <module>
from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'
Código:
from sklearn import tree #importando a biblioteca e a árvore p/ o classificador
#COLLLECT TRAINING DATA
features = [[140,1],[130,1],[150,0],[170,0]]
labels = [0,0,1,1]
# TRAIN CLASSIFIER
clf = tree.DecisionTreeClassifier() #Classificador
clf = clf.fit(features, labels) #algoritmo de decisão p/ encontrar padrões
#MAKE PREDICTIONS
print(clf.predict([[160, 0]])) #entrada de dados para o tratamento
Try this:
python -m pip install --upgrade scipy
After digging in, to give the full background on this, first of all SciPy relies on having NumPy already installed. The SciPy wheel's setup.py file uses NumPy functionality to configure and install the wheel.
SciPy setup.py:
...
if __name__ == '__main__':
from numpy.distutils.core import setup
setup(**configuration(top_path='').todict())
Secondly, when just trying to use the wheel, if you run into this error, you can see after inspecting the wheel's files that the reason is the binary wheels have a naming convention where the shared object file, here it's called _ccallback_c.so, is instead named based on the architecture that the binary wheel supports. When trying to import the shared object by file name in /_lib/_ccallback.py it can't find it, hence this error (line 1 in /_lib/_ccallback.py) because, instead of being named _ccallback_c.so it's called _ccallback_c.cpython-36m-x86_64-linux-gnu.so or another architecture variation:
from . import _ccallback_c
These file names seem to be an artifact of libraries that are using Cython and Cython's adherence to PEP 3149 (ABI version tagged .so files). But the easiest fix is to change the .whl extension to .zip and rename all those relevant .so files to not contain the architecture snippet. Then change .zip -> .whl and it should be good to go unless it's the wrong architecture for the platform you're using, in which case you need to download the appropriate platform wheel for your platform.