Sublime Text2 Import error: No module named Gnuplot - python

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

Related

Module Not Found Error for 'pdf2image' in Python Script

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.

Vscode gives "ModuleNotFoundError", when running python script with right corner arrow

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.

ImportError for every third party library

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

Need help manually installing nltk

I downloaded the nltk package from https://github.com/nltk/nltk_data (I cannot use nltk.download() due to proxy issues) and put it at C:\nltk_data. When I try 'import nltk' from the python interpreter I get this error message:
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named nltk
I do not know how to get the python interpreter to see the folder. Any help would be greatly appreciated.
Thanks!
In my opinion, the Python interpreter will check the library path before its running.
You can use sys.path in python interpreter to check the place.
Always by default, python will add the running path to the library path which in linux like "./".
If you want to run the python in another path, In Windows there are two ways to solve this problem.
You can add a environment variable
C:\Users\Administrator>set PYTHONPATH=C:\nltk_data
Or you can add it in you python script like:
sys.path.append("C:\nltk_data")
PS:
Dobule check the path(\ or /) which is in different types between Windows and Linux.

Multiple programs installing python modules on computer, confusing the crap out of IDLE

Most of the programs I use for my work have independent python API's which do various things. The downside to this is that it appears that each program installs its packages wherever it wants. This is by way of introduction.
Now, I am trying to run matplotlib through IDLE. I ran a clean pip upgrade and the ran a clean install of matplotlib using pip in cmd. The commands I used were found in this document, page 13.
When I try to import matplotlib in IDLE, I get the following error message:
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib
File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\Lib\site-packages\matplotlib\__init__.py", line 727
except Exception, msg:
The path it points to is for an independent program named Paraview which has its own set of python modules. It looks like Paraview also has a definition for matplotlib but I don't want to use this one. A quick snip of the paths in IDLE shows:
It looks like IDLE is prioritizing the Paraview folder over the others. How do I get IDLE to disregard this folder and look into the matplotlib module I just installed by default? Also how do I prevent this unfortunate and seemingly unnecessary duplication of modules?

Categories

Resources