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
Related
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?
I am using a Macbook Air with OS X Yosemite.
I am using python 3.4.3.
This morning I opened my laptop and entered import pygame and when I ran the program I got the response:
Traceback (most recent call last):
File "/Users/Samantha/PycharmProjects/RPG/code.py", line 2, in <module>
import pygame
ImportError: No module named 'pygame'
I opened IDLE and also did import pygame and it worked! (perhaps the paths are mixed up?)
For some reason it does not want to work in pycharm anymore.
My pycharm app has been acting quite strange since pygame was "un-import-able"; first it did not want me to create a new python file and then I wasn't allowed to run any of my other programs. please help! thanks
You probably have wrong Python interpreter speicfied in PyCharm preferences. Go to
PyCharm -> Preferences... -> Project: project -> Project Interpreter
and from the dropdown list choose your Python interpreter or add it manually if PyCharm is not seeing it.
I writing a small standalone GIS application, with some tools from QGIS and GUI made with PyQt. Im trying to import qgis modules like qgis.core and qgis.gui into my python programm, and failing hard no matter how i try.
Im using:
Python 3.4 (C:\Python34) + PyCharm
QGIS 2.2 (C:\Program Files\QGIS_2.2)
I set my environment-variables this way:
PYTHONPATH, i added C:\Program Files\QGIS_2.2\apps\qgis\python\
(there is other items before that, if its matters)
Path, i added C:\Program Files\QGIS_2.2\apps\qgis\bin - where all qgis
.dll files seems to be.1
I read every single topic i found on google, every related question on stackoverflow, set my environment-variables in a million of different ways, nothing seems to work. I get this error message every time.
C:\Python34\python.exe F:/PyCharm_Projects/Project_1/Testing_Area.py
Traceback (most recent call last):
File "F:/PyCharm_Projects/Project_1/Testing_Area.py", line 3, in <module>
import qgis.core
File "C:\Program Files\QGIS_2.2\apps\qgis\python\qgis\__init__.py", line 35, in <module>
from qgis.core import QgsFeature, QgsGeometry
ImportError: DLL load failed: The specified module could not be found.
Process finished with exit code 1
If i just run QGIS desktop, and execute import qgis.core in it's buildin python console, it works, no errors.
I'm a new user, so i think i may be missing somthing simply. So please if you know what may be wrong, tell me. I dont understand, i suppose to write my standalone application based on QGIS inside QGIS python console? Can't i use my Python 3.4 with all my needed modules installed?
1. I'm not sure to which variable (system Path, or user PATH) i should add this. I tried both and none of them worked.
2. PyCharm give me this warning every time. Maybe it will help. PyCharm Warning
I wrote myself a small Python script that I want to use to automatically do things with certain types of files; as such, I want to create an .app out of it so that I can set certain files to be opened with it automatically.
So I looked around and found Platypus which seems to do what I need.
However, weirdly it doesn't work. Specifically, it does not seem to be finding the right python interpreter. I set it up as follows:
I.e., the script type is env so it should just read the top line of the file like the shell does.
In magic.py, the top line is #!/usr/bin/env python2.7.
Now, when I run the shell script on the command line (that is, ~/devel/magic.py whatever), everything works fine. But when I run the app, it errors with:
Traceback (most recent call last):
File "/Users/jan/Dropbox/devel/Magic.app/Contents/Resources/script", line 8, in <module>
from bencode import *
ImportError: No module named bencode
The same import works just fine when running it from the command line, so I'm thinking it's using the wrong interpreter somehow. How can I fix or debug this?
You are trying to import from bencode module but you didn't add it in the application's bundled resources. Either drag it to the list of included files and export again or just copy it to the resources folder in the package's contents.
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