I am working on a project to extract text from a bunch of scanned PDF's. I am following this tutorial. One of the first steps involves importing modules. I'm having some trouble importing 'pdf2image'. For context, I'm using a Conda environment called, "textExtractor" in VS Code's Python terminal. I checked if pdf2image was installed by running "Conda list" and it looks to be installed. However, when I run the python script I get an error saying,
(textExtractor)
C:\Users\mhiebing\Documents\GitHub_Repos\MonthlyStatsExtract>C:/Users/mhiebing/Anaconda3/python.exe
c:/Users/mhiebing/Documents/GitHub_Repos/MonthlyStatsExtract/PDF_to_Image.py
Traceback (most recent call last): File
"c:/Users/mhiebing/Documents/GitHub_Repos/MonthlyStatsExtract/PDF_to_Image.py",
line 1, in
from pdf2image import convert_from_path, convert_from_bytes
ModuleNotFoundError: No module named 'pdf2image'
Below is a screenshot showing pdf2image and the error:
Any idea what's going wrong?
The python interpreter you selected is not the textExtractor but the mhiebing.
You can click the Status Bar of interpreter to switch the interpreter. And you can refer to the official docs for more details.
It looks like you type the command to run the file, it's not recommended. You can click the green triangle button on the top right corner or the F5 to debug it. If you do that you can find out the truthly environment you are taking.
Related
All of my project files in VS code suddenly gives an error saying that it cannot import modules (even tho the modules are local i.e same directory and they used to work pretty well before).
The code works fine in pycharm but not in VS code, any idea whats going on?
Code:
from backend.util.crypto_hash import crypto_hash
from backend.config import MINE_RATE
error:
env DEBUGPY_LAUNCHER_PORT=34625 /home/nikhil/python-blockchain/blockchain-env/bin/python /home/nikhil/.vscode/extensions/ms-python.python-2020.3.71659/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher /home/nikhil/python-blockchain/backend/app/__init__.py
Traceback (most recent call last):
File "/home/nikhil/python-blockchain/backend/app/__init__.py", line 2, in <module>
from backend.blockchain.blockchain import Blockchain
ModuleNotFoundError: No module named 'backend'
Close VS Code,
start it again, Go to File > open folder (open your project folder in vs code),
if it gives a prompt to select a existing virtual environment, select that.
Then you should be good to go.
More unrelated information:
I assume the issue here is that there's some problem with VS Code not recognizing the virtual environment properly. This has happened to me several times and I cannot point out why that happens. But the above solution is a quick fix and always works for me.
I'm not sure if this will resolve OP's (ten-month old) question, but I've been struggling with the same error using debugpy while trying to configure VSCode's debugger.
Step 4 of this resource resolved the issue for me. In particular, I was using the -m flag when running debugpy, but the module to be run was not in the current working directory. Once I had changed this, the debugger worked as expected. As an example, if the command was originally:
python -m debugpy --listen 0.0.0.0:5678 ./some/directory/my_script.py
then the following two commands would rectify it:
cd ./some/directory
python -m debugpy --listen 0.0.0.0:5678 ./my_script.py
After doing this, I no longer received the "No module found" error.
The main reason is that VSCode does not automatically configure environment variables for you, but PyCharm does. The simplest method is adding your module file to system path.
import sys
sys.path.append(module_file_path)
The better solution is to config your environmental path named PYTHONPATH, adding related module path to it, and after that you will no longer need import system path manually.
Hope it works!
When debugging, this works ok, but when running without debugging, I get the error.
I tested with one line:
import fiona
Traceback (most recent call last):
File "d:\own\fionatest.py", line 1, in <module>
import fiona
ModuleNotFoundError: No module named 'fiona'
Fiona functions also work ok, when debugging, but for simplicity, I explain the situation with this one line. I can run the same script from windows command prompt normally without errors.
As explained here, debugging has specific settings on a launch file, and when in this mode the access to variables and paths might be changed as compared to the Run Python File in terminal option (which is what the arrow button does).
Therefore, I would assume that your module is not properly installed to be used in the environment you are trying to run the script. It might be helpful to know your Operational System and how someone can reproduce this behavior (as indicated in this link).
What to try
Uninstalling the module and reinstalling it, then restarting all the instances of VSCode and trying again, both the debugging and the arrow button. If the same behavior persists, probably you need to check the Python Path variables and which interpreter VSCode is using to run the Python scripts, and make sure it is the same used as reference for installing new modules.
Also, this answer might help shed a light to your situation.
I created a project in Pycharm including a gp.py, copied the project folder to another machine and tried to run the gp.py script from command line using python gp.py. However I got a error
Traceback (most recent call last):
File "gp.py", line 2, in <module>
from gplearn.genetic import SymbolicRegressor
ModuleNotFoundError: No module named 'gplearn'
The thing is I could see this gplearn library I used in the project folder, like below. The screen shot is not from Pycharm but the folder I copied to another computer. I tried to place the gp.pyinside and outside venv folder but neither worked. Could you please help to point out what the problem is ? Many thanks
gplearn package is not installed in the new machine.
Go to cmd prompt/terminal in pycharm and execute below line:
pip install gplearn
Sound like you are seeking for a method to deploy your script to end user, in this case maybe you can give Pyinstaller a try.
I know there are similar questions, but I've looked at them and none of them are what I'm looking for
I'm running Python 3.7.0 on Windows 10, and I installed pygame-1.9.4 a few weeks ago, and it's been working fine until yesterday.
I have a file called testing.py that just contains:
import pygame
when I run it via
C:\Users\Me>testing.py, it returns the following error:
Traceback (most recent call last):
File "C:\Users\Me\testing.py", line 1, in <module>
import pygame
ImportError: No module named pygame
But when I'm in the Python shell, I can import it just fine
This is the case for every third party library. I have tested Pillow, flask, and others. Importing from the standard library works fine
I have uninstalled and reinstalled python and pygame, I've updated pip, I've updated setuptools as one person suggested, but none of it works
I had been using Wing IDE personal 6, and I could also run it fine from there, but I didn't care for it. Please help!
I am guessing that there are multiple python versions on your system and the one associated with .py files is not the one that you are using in the other cases.
To debug, what you can do is:
Write in a .py file
import sys
print(sys.executable)
and also execute those lines from your python shell. That will print the path to the python interpreter that is executing said commands. The result will probably be different in your case.
What you can also do is check if
print(sys.path)
results in the same list using both methods, as it contains the folders being searched when importing
I'm trying to use Gnuplot in a Python script I'm writing in Sublime Text. Whenever I build, I get the error message
Traceback (most recent call last):
File "..." line 4, in <module>
import Gnuplot
ImportError: No module named Gnuplot
If I do the exact same code lines directly in Terminal, I have no problem importing and using Gnuplot.
The import error seems to be common, just with other modules. Usually the fix is related to PYTHONPATH. However, Gnuplot is on my computer located in
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
and should thus be found.
Anybody who's got a fix to this one?
Sublime Text 2 comes with its own Python interpreter which sets PYTHONPATH independently from the system Python interpreter you are referring to.
Please see this question how to set a different PYTHONPATH for Sublime. Please note that if the library you are using was compiled against a different Python version than Sublime is using loading the native dynamically linked libraries will probably cause Sublime Text 2 to crash.
https://stackoverflow.com/a/9919953/315168