I have a problem with PyCharm. I start learning python with PyCharm and I want write some with turtle package. When i try execute this code
import turtle
bob = turtle.Turtle()
I have that message:
"C:\Program Files\Python36\python.exe" C:/Users/Ptr/Desktop/python/Proj_1/Gui.py
Traceback (most recent call last):
File "C:/Users/Ptr/Desktop/python/Proj_1/Gui.py", line 1, in <module>
import turtle
File "C:\Program Files\Python36\lib\turtle.py", line 107, in <module>
import tkinter as TK
File "C:\Users\Ptr\Desktop\python\tkinter.py", line 3, in <module>
okno = tkinter.Tk()
AttributeError: module 'tkinter' has no attribute 'Tk'
Process finished with exit code 1
When I try execute that code using IDLE all works.
In PyCharm I try install turtle in project:
Python>Project Interpreter
but all time I have same error:
Collecting turtle
Using cached turtle-0.0.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Ptr\AppData\Local\Temp\pycharm-packaging\turtle\setup.py", line 40
except ValueError, ve:
except ValueError, ve:
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Ptr\AppData\Local\Temp\pycharm-packaging\turtle\
enter code here
A couple of things to note for those running into this at a later time:
tkinter must be installed on your machine. There is a python2.x and
python3.x version. It must match your version of python. For example,
In Ubuntu, I am running python3.6, and had to run apt-get install
python3.6-tk
Pycharm allows you to pick interpreters. It is possible to be running
a different interpreter in IDLE than in PyCharm, making the mismatch
of python and tkinter versions potentially confusing. This is further
complicated potentially by virtual environments. Be certain your
python version and you tkinter versions match.
You can not have modules in your import path of the name tkinter.py or turtle.py
As mentioned by ds_secret, turtle comes with python, no need to
install it separately.
You don't pip turtle. Turtle is a built-in python package.
You just say import turtle.
Related
Python noob here. I've been trying to install pygame and pandas for a few hours now. Even with Conda I did not succeed. I have Python 3.8.5 installed.
I eventually tried through the terminal with these commands:
python -m pip install pygame==2.0.0.dev6
and
python -m pip install pandas
(this was a total guess by the way, but apparently it did something)
Results were succesfull:
Requirement already satisfied: pygame==2.0.0.dev6 in /opt/miniconda3/lib/python3.8/site-packages (2.0.0.dev6)
and
Successfully installed numpy-1.19.2 pandas-1.1.2 python-dateutil-2.8.1 pytz-2020.1
But, when I try to import either modules, I still get errors. Any ideas?
import pygame
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
import pandas
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
Do I need to move the modules to the script folder or something? Or what do I even move? Thanks!
Ok.. Got it thanks to #matt.. after succesfully installing pygame, find the environment in which pygame is installed by entering 'which python'.
In my case it returned:
/opt/miniconda3/bin/python
Now I needed to make sure the VS console was pointing at the same environment, by checking which python interpreter it was using and selecting the correct one. More info:
how to check and change environment in VS Code
When importing PyGame using the interpreter it is successful. Using Geany it is not.
shows the error.
I have tried editing the shebang, renaming the file. making sure the PATH and version were correct, and that there were no missing Geany plugins.
import pygame
pygame.init()
Error in Geany:
Traceback (most recent call last):
File "moduleerror.py", line 3, in <module>
import pygame
ImportError: No module named pygame
I went into Build >> Set Build Commands and under Execute commands changed
python "%f"
to
python3 "%f"
I've been trying to install pyautogui for Python 3.4 on my Raspberry Pi 3 for the last 2 hours... I need it because I wrote a touch keyboard application that needs to run on it. On my main machine (elementary OS 0.4 with Python 3.5) I was able to install it without any problems. First I tried sudo pip install pyautogui but that only installed the Python 2.7 version of pyautogui. Of course next I tried sudo pip3 install pyautogui but that gave me this error:
Running setup.py (path:/tmp/pip-build-hf289jja/pyautogui/setup.py) egg_info for package pyautogui
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip-build-hf289jja/pyautogui/setup.py", line 6, in <module>
version=__import__('pyautogui').__version__,
File "/tmp/pip-build-hf289jja/pyautogui/pyautogui/__init__.py", line 114, in <module>
from . import _pyautogui_x11 as platformModule
File "/tmp/pip-build-hf289jja/pyautogui/pyautogui/_pyautogui_x11.py", line 6, in <module>
from Xlib.display import Display
File "/usr/local/lib/python3.4/dist-packages/Xlib/display.py", line 20, in <module>
import new
ImportError: No module named 'new'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 17, in
File "/tmp/pip-build-hf289jja/pyautogui/setup.py", line 6, in
version=__import__('pyautogui').__version__,
File "/tmp/pip-build-hf289jja/pyautogui/pyautogui/init.py", line 114, in
from . import _pyautogui_x11 as platformModule
File "/tmp/pip-build-hf289jja/pyautogui/pyautogui/_pyautogui_x11.py", line 6, in
from Xlib.display import Display
File "/usr/local/lib/python3.4/dist-packages/Xlib/display.py", line 20, in
import new
ImportError: No module named 'new'
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-hf289jja/pyautogui
Storing debug log for failure in /root/.pip/pip.log
... sorry for the formatting of the above, I couldn't get it to stay inside one code box.
I have no idea what module "new" is. I tried everything else under the sun, such as installing from the official resources: https://pypi.python.org/pypi/PyAutoGUI and various other guides, with NO results.. I'm kinda loosing my mind right now.
ANY Help is grately appreciated :)
Try the following:
sudo pip3 install python3-xlib
sudo pip3 install pyautogui
This assumes you have some other python3 libraries already installed, but you will see missing installs in the above if not.
that's my first question here.
I have a problem with python3.5 and PyAudio on my Ubuntu 16.04:
What type of problem I have
Currently I'm writing on a program that uses the speech_recognition library in python.
And if I call my script (python3 processor.py), it says the following:
Traceback (most recent call last):
File "processor.py", line 143, in <module>
main()
File "processor.py", line 132, in main
with sp_reco.Microphone() as source:
File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 55, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 88, in get_pyaudio
raise AttributeError("PyAudio 0.2.9 or later is required (found version {0})".format(pyaudio.__version__))
AttributeError: PyAudio 0.2.9 or later is required (found version 0.2.8)
Checking existing pip3 modules with pip3 list gave me the following:
PyAudio (0.2.9)
And I don't know why speech_recognition says the found version is 0.2.8
And it works if I type python3 in the console and type in the shown python console import pyaudio
My script works fully, if I use the python command
Screenshot pip3 list
Does unirest support python3? I have googled and zero information comes up. Even in the unirest documentation it does not say it is 2.x only which leads me to believe it supports both 3.x and 2.x. However the install fails with 3.4 and succeeds with 2.7. See below.
nkltss:~/dev$ mkvirtualenv mashape -p /usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in mashape/bin/python3
Also creating executable in mashape/bin/python
Installing setuptools, pip...done.
(mashape)nkltss:~/dev$ pip install unirest
Downloading/unpacking unirest
Downloading Unirest-1.1.6.tar.gz
Running setup.py (path:/home/nick/.virtualenvs/mashape/build/unirest/setup.py) egg_info for package unirest
warning: no files found matching '*.txt' under directory 'docs'
Downloading/unpacking poster>=0.8.1 (from unirest)
Downloading poster-0.8.1.tar.gz
Running setup.py (path:/home/nick/.virtualenvs/mashape/build/poster/setup.py) egg_info for package poster
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/home/nick/.virtualenvs/mashape/build/poster/setup.py", line 2, in <module>
import poster
File "/home/nick/.virtualenvs/mashape/build/poster/poster/__init__.py", line 29, in <module>
import poster.streaminghttp
File "/home/nick/.virtualenvs/mashape/build/poster/poster/streaminghttp.py", line 61
print "send:", repr(value)
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/home/nick/.virtualenvs/mashape/build/poster/setup.py", line 2, in <module>
import poster
File "/home/nick/.virtualenvs/mashape/build/poster/poster/__init__.py", line 29, in <module>
import poster.streaminghttp
File "/home/nick/.virtualenvs/mashape/build/poster/poster/streaminghttp.py", line 61
print "send:", repr(value)
^
SyntaxError: invalid syntax
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/nick/.virtualenvs/mashape/build/poster
Storing debug log for failure in /home/nick/.pip/pip.log
For now I am using 2.7 but I prefer to use 3.x for new projects.
The project is not Python 3 compatible. When the project doesn't explicitly state this (not in the setup.py trove classifiers nor in documentation), you'll have to look at the source code.
There I find:
no use_2to3 use in setup to automatically rewrite code on install
imports for urllib2, a Python 2 only library.
The project depends on the poster library, which is also urllib2 specific.
I'd use the requests library instead. It supports Python 3 out of the box, and apart from asynchronous requests it supports the same feature set (but better as it doesn't have the shortcomings urllib2 brings along). For asynchronous requests, you can add on requests-futures.