suddenly I can't import pygame when using pycharm5 - python

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.

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.

MacOS: different treatment of IDEs and terminal when running code?

I am having a problem with a python IDE (Sublime) on macos when trying to use ktinter:
I set up a clean mac and installed Python 3.7 via the normal installer (with the box ticked to install tkinter)
The problem I am having now is this: When I write code in Sublime and try to run it within the IDE (Sublime -> Tools -> Build) I get an error message.
Code
import tkinter as tk
tk._test()
Output
Traceback (most recent call last):
File "/Users/christiankoch/Desktop/sys.py", line 1, in <module>
import tkinter as tk
ImportError: No module named tkinter
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/christiankoch/Desktop/sys.py"]
[dir: /Users/christiankoch/Desktop]
[path: /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
However, when I just save the file and run it in the terminal everything works fine and I see the test window.
In the terminal
python3 test.py
So ultimately I am confused about different outcomes of the two approaches. When I use Sublime on Windows it works perfectly fine; and even using pyCharm on macos works for tkinter. So I am confused what the problem is.
When you run file.py from the console, the executable as specified in the environment variables is used by default.
In sublime you probably using a build system, that points to another environment/ executable. You should have a look at https://youtu.be/xqcTfplzr7c
And follow the instructions.

ModuleNotFoundError: No module named zenpy on PyCharm (Mac)

I'm not too familiar with mac, but I fired up pycharm to run a script I made that uses the zenpy module. Problem is when I try to execute it, I get the error
Error Message:
Traceback (most recent call last):
File "/Users/thisisfake/PycharmProjects/untitled1/venv/bin/test.py", line 29, in <module>
from zenpy import Zenpy
ModuleNotFoundError: No module named 'zenpy'
The obvious answer is, oh, I forgot to add the module to zenpy. So I went to File -> Preferences for New Projects -> Project Interpreter and added zenpy. Tried the script again, no dice. Check the project interpreter and zenpy is definitely there. I tried creating a new project entirely and re-adding it that way and no success. Tried moving the script to the bin folder, no luck. Added zenpy via pip in terminal, same result. I'm definitely missing something obvious, any idea what it is?
Thanks!
Select View -> Tool Windows -> Terminal
pip install zenpy

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

Import requests working on Windows shell but not in PyCharm

The simple import of requests
import requests
can be executes and used in windows shell but the same code says in pycharm:
Traceback (most recent call last):
File "C:/Users/XPS13/PycharmProjects/Testing/Webcrawler_Test.py", line 1, in
<module>
import requests
ModuleNotFoundError: No module named 'requests'
requests was correctly pip installed. Even uninstalling and reinstalling doesn't work.
Any help would be appreciated.
Yeah so this might be a little late but I fixed my problem like this:
Go to Settings/Preferences
Select Project Interpreter
And press the + button on the left side
That + sign
Search for requests
And press Install Package
I am running:
Windows 10
Python 3.7.1
You need to configure the project interpreter in PyCharm:
Go to Settings/Preferences
Select Project Interpreter
Click the little gear and click Add...
Select the appropriate interpreter (whether a virtual environment or system python installation)
Settings top right
'+' above Package table
Search: Requests & highlight in list
Install Package

Categories

Resources