This question already has answers here:
pdfminer - ImportError: No module named pdfminer.pdfdocument
(4 answers)
Closed 4 months ago.
I have found a few solutions here and elsewhere, but none of them has worked. Context: I am trying to get pdf2txt going on my Pop!_OS 22.04 LTS system. I am using Python 3.10.6, with no other versions present. The command-line states that it requires python3-pdfminer to work, which I installed with apt. Output states that there is no module named 'pdfminer.high_level'. This comment here notes that it's a part of pdfminer.six which can be installed using pip, using a dash instead of a dot if it's inside a virtual environment.
$ python3 -m pip install pdfminer.six
states that requirements are already satisfied. To be sure, I also switched to a virtualenv and installed it there:
$ pip install pdfminer-six
Running pdf2txt in both cases results in the same error, i.e.
File "/usr/bin/pdf2txt", line 9, in <module>
import pdfminer.high_level
ModuleNotFoundError: No module named 'pdfminer.high_level'
I then tried to uninstall and reinstall pdfminer.six, first on the system wide version. python3 -m pip uninstall pdfminer.six (or just pip3) was not allowed, so I made a judgment of error and used sudo. Reinstalling now shows:
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pdfminer.six in /usr/lib/python3/dist-packages (-VERSION-)
so I am not sure if it is properly installed. So I tried in the virtualenv where there were no problems. But the same error remains.
I reinstalled python3-pdfminer but without success.
In the virtualenv, I found:
./lib/python3.10/site-packages/pdfminer/high_level.py
./lib/python3.10/site-packages/pdfminer/__pycache__/high_level.cpython-310.pyc
I then created a test Python file that imports pdfminer.high_level and ran it, with no problem. I then did the same outside the virtualenv. pdfminer is imported correctly, but it can't import pdfminer.high_level. So I found the following:
When I uninstall pdfminer.six, it looks in /usr/local/lib/python3.10/dist-packages and removes it from there.
When I install pdfminer.six, it looks in /usr/lib/python3/dist-packages. Here, the high_level package is present. But the system always looks in /usr/local/lib/python3.10/dist-packages, so the package is never found.
So, I think that I found the cause of the problem. Running pdf2txt doesn't work in the virtualenv because it's still a file in /usr/bin that will look for a system-wide version. I suppose that I can update a system environment path to point to /usr/lib/python3/dist-packages, and solve it like this (pdf2txt is actually not binary so I can append to sys.path). But why has this discrepancy occurred in the first place? And what is the proper way to deal with it? After all, there is a reason why some packages are installed in different locations.
Many thanks.
EDIT: Adding to sys.path doesn't work, but adding to PYTHONPATH does. Not sure if this is something that I should watch out for in the future, or just a result of a Python executable installed in /usr/bin messing up with the idea of using a virtualenv in the first place.
Sometimes this issue happens when you have same name file in your working dir. So please check that first like if you have a file name "pdfminer.py".
If that is not the case then I usually try the previous version of lib.
you can try installing previous version with
pip install pdfminer.six==20220506
My code fails when it tries to import requests, despite it already being installed. I did a pip list and saw the module requested there, I uninstalled it and reinstalled it with both pip install and pip3 install, also added sudo both times. Whenever I try to install it I get the message that the requirement is already satisfied. Is there something else that I could try?
If it helps I am using VSCode on a Mac, I also have Jupyter and Spyder installed and have used them before however I’ve never used the requests module on this device.
UPDATE:
I created a virtualenv and installed requests there, when running the script in the venv I am not getting the error anymore, however I am still curious why it was being thrown on the base env, anything else I could check?
You probably have multiple installations/environments.
Before the "import requests", line put "import sys; print(sys.executable)".
This prints the python executable being used - verify that it is the same one that you can successfully import requests with .
What worked for me was deleting three folders having names starting with "request-SOMETHING" in the directory that pip3 specifies when you try to install requests again, e.g.
Requirement already satisfied: requests in /usr/lib/python3/dist-packages
Then just reinstall with pip and it should be in your sys.executable directory.
Try this
pip install chardet2 urllib3
or
python3 -m pip install requests
There is a problem with package dependency
I have installed the module alpha_vantage using pip. In CMD writing import alpha_vantage does not show an error message, so I assume it is installed properly.
However, when trying to import alpha_vantage in a python program I get this error: "ModuleNotFoundError: No module named 'requests'". I assume the issue is due to the location of the module.
The project is located here:
C:\Users\M\Documents\Python\Investering.
I tried placing the module here by pip: C:\Users\M\Documents\Python\Investering\modules\alpha_vantage
Note pip did not install the module there I simply copied the module folder and placed them in the project folder.
Is it possible to simply copy and paste module folders in other projects? Or how am I supposed to make python acknowledge the module?
The module was installed here:
C:\Users\M\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\alpha_vantage
I'm quite new to python. I have tried adding to sys.path the folder where the module was installed, but it did not seem to help.
Thanks for any help.
Edit: I tried pip install requests and it produced this:
Requirement already satisfied: requests in c:\users\martin\appdata\local\programs\python\python38-32\lib\site-packages
Someone mentioned running: "pip install foo"
It, however, produces this error message:
ERROR: Could not find a version that satisfies the requirement foo (from versions: none) ERROR: No matching distribution found for foo
I am using PyCharm.
I found my error. I had installed python from the website, but had unknowningly installed the 32 bit version, and a 64 bit version. I uninstalled all my python versions and pycharm. Then I reinstalled everything. Now I could easily make the module work. Thanks for the pointers.
I need to import
1.yaml
2.pypiper
modules to the latest PyCharm IDE. I can not find pypiper in the list of available modules. When I am trying to add a new repository for the pypiper:
https://github.com/epigen/pypiper.git
still the same: typing pypiper in the search field does not yield anything.
yaml at the same time can be found, but it is giving me an error when I am trying to add it:
Could not find a version that satisfies the requirement yaml (from versions: )
No matching distribution found for yaml
PyCharm looks for packages in the repositories that it has been told to look in. By default it looks at https://pypi.python.org/simple.
Effectively this means that if you cannot install something through pip, you cannot install through the PyCharm interface.
What you need to do is to figure out:
How to install yaml
sudo pip install pyyaml
How to install pypiper
pip install --user https://github.com/epigen/pypiper/zipball/master
When I run into these issues it's easiest for me to just install on the command line opposed to through PyCharm unless it's a virtual env. Just make sure your pip is referencing the same python interpreter you are using in PyCharm or you still wont see it in PyCharm.
I am using Python 2.7 and I want to use pywin32-214 on Windows 7. I installed pywin32-214 by using the MSI installer. But when I import win32api in my Python script, it throws the error:
no module named win32api
What should I do? How can I use win32api on Windows 7?
This is resolve my case as found on
Where to find the win32api module for Python?
pip install pypiwin32
According to pywin32 github you must run
pip install pywin32
and after that, you must run
python Scripts/pywin32_postinstall.py -install
I know I'm reviving an old thread, but I just had this problem and this was the only way to solve it.
I had an identical problem, which I solved by restarting my Python editor and shell. I had installed pywin32 but the new modules were not picked up until the restarts.
If you've already done that, do a search in your Python installation for win32api and you should find win32api.pyd under ${PYTHON_HOME}\Lib\site-packages\win32.
I didn't find the package of the most voted answer in my Python 3 dist.
I had the same problem and solved it installing the module pywin32:
In a normal python:
pip install pywin32
In anaconda:
conda install pywin32
My python installation (Intel® Distribution for Python) had some kind of dependency problem and was giving this error. After installing this module it stopped appearing.
I had both pywin32 and pipywin32 installed like suggested in previous answer, but I still did not have a folder ${PYTHON_HOME}\Lib\site-packages\win32.
This always lead to errors when trying import win32api.
The simple solution was to uninstall both packages and reinstall pywin32:
pip uninstall pipywin32
pip uninstall pywin32
pip install pywin32
Then restart Python (and Jupyter).
Now, the win32 folder is there and the import works fine. Problem solved.
After installing pywin32
Steps to correctly install your module (pywin32)
First search where is your python pip is present
1a. For Example in my case location of pip -
C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts
Then open your command prompt and change directory to your pip folder location.
cd C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts
C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts>pip install
pypiwin32
Restart your IDE
All done now you can use the module .
The following should work:
pip install pywin32
But it didn't for me. I fixed this by downloading and installing the exe from here:
https://github.com/mhammond/pywin32/releases
This line:
import win32com
got me the error no module named win32api.
Using this command in elevated terminal:
pip install pywin32-ctypes and
pip install pywin32
and based on the error displayed, replacing:
import win32api → from win32ctypes.pywin32 import win32api
import pywintypes → from win32.lib import pywintypes
import _win32sysloader → from win32 import _win32sysloader
in your source file, or even the files of the packages that report the error (know what you are doing if you choose this approach) may solve this error. But better would be to just add the corresponding directories into the python path variable, for better integration with the python loading system, more info here: https://realpython.com/python-import/
So I put this content:
python38.zip
.
./lib
./lib/site-packages
./lib/site-packages/win32
./lib/site-packages/win32/lib
./lib/site-packages/win32ctypes/pywin32
./lib/site-packages/win32ctypes
# Uncomment to run site.main() automatically
#import site
(order DOES matter)
into this file: <python_root_installation_directory>/python38._pth
That way, correct libraries load when standard imports are used. If there is a cache import somewhere in the library, it will work, and the imports inside the libraries work as well.
This works for me and my installation, so your environment may be set up differently and this guide may not be fully compatible, but it is a good step in solving the issue, maybe modification or extension of my steps above may lead to the solution in another distribution.
Try this, it worked for me, it may help you!
pip install pywin32==225
I've tried all of your answers and finally got a solution. my issue was that I installed from both pip and python interpreter on my Pycharm IDE. I just removed win32compact from my interpreter and it works.
let me summarize, correct me if wrong, as below:
# update to newest pywin32
python -m pip install -U pywin32 pypiwin32
# run the post-install #ref https://stackoverflow.com/questions/21343774/importerror-no-module-named-win32api
python %CONDA_PREFIX%\Scripts\pywin32_postinstall.py -install
# double check
python -c "print( __import__('win32api') )"
In my case, the only thing that worked was to download the appropriate wheel from: https://pypi.org/project/pywin32/#files, and install with --force-reinstall.
pip install pywin32-300-cp37-cp37m-win_amd64.whl --force-reinstall
I found solution here:
https://www.ti-enxame.com/pt/python/pywin32-e-python-3.8.0/813327700/
I was able to run it on Spyder without error, but It wasn't working on cmd prompt
I just import the module pywintypes before win32api
import pywintypes
import win32api
I tried to reinstall pywin32, installed different versions, but nothing could make pywin work. The only thing that did finally help me was running
python pywin32_postinstall.py
which is located at Anaconda3\Scripts folder. Thanks for sameer_nubia for highlighting the location.
I solve this by
python -m pip install -U pywin32 pypiwin32