1) I am getting error on the python script if i run it through sublimetext. How do i map my existing python to sublime text rather than using the one comes with sublimetext ?
import Tkinter as tk
import tkinter
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named tkinter
i think the tool use its own python.
2) is there a short key like (the common F5) to run the script on sublimetext ?
Please suggest.
Thank you
The Python builder in Sublime Text runs the active Python file with the Python executable found in your PATH. You can start it with Tools -> Build (Ctrl + B).
Related
I have recently changed my text editor from IDLE to Atom but when I started to run my program that i have ran in the past eg(music player using pygame) it didn't work and came up with this error message:
Traceback (most recent call last):
File "/Users/jacquelinethompson/Desktop/Untitled.py", line 1, in <module>
import pygame
ImportError: No module named pygame
[Finished in 0.088s]
I checked the import to see if it worked in IDLE and it works fine there. Can anyone explain why and how to fix it.
I am on the MacOS and am using python3.6
I'm trying to open an Excel file using Pycharm, but always get a the following message:
Traceback (most recent call last):
File "C:/Users/.../PycharmProjects/Excelmodules/openxlsx.py", line 2, in <module>
from openpyxl import openpyxl
ImportError: cannot import name 'openpyxl' from 'openpyxl' (C:\Users\...\PycharmProjects\Excelmodules\venv\lib\site-packages\openpyxl\__init__.py)`
Process finished with exit code 1
I have successfully installed Openpyxl in Pycharm (using another thread on stackoverflow) and have checked the file name/path is correct, but still get the error message.
I am new to python so it might be something I have/haven't done, but the only things I can think are causing this are:
running it through Pycharm rather than command prompt
Windows 10 did a forced update and created an "old windows folder and I'm wondering whether Pycharm or openpyxl are trying use/run using the old.windows folder
the Excel file needs to be in the Pycharm folder
I was starting a project in Automate the Boring stuff, but can't get past this step.
Please help!
Thank you
Rob
I ran a python file, named jbA.py in windows command prompt, with the following commands, orderly:
python
jbA.py
It displays the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'jbA' is not defined
Can anyone help to fix the above mentioned error? Thank you.
when you type python you are moving to the python commandline tool. Now there is no context for your file jbA.py.
To execute a python file, type python <filename>.py.
In your case, it is python jbA.py. For python 3.x, you may use python3 jbA.py
Have you checked that python is in your Environment PATH variable list? Try typing
python --version
in your windows command prompt and see if you get an error. If it does not return a version number, it has not been added to your PATH.
If you don't know how to do this, refer to this link -
https://www.java.com/en/download/help/path.xml
To run pyhton script
open command prompt
1) for python version greater then 3:- python3 filename.py
2) for python version 2:- python filename.py
no need to open python console
Code in question:
from tkinter import *
root = Tk()
test_label = Label(root, text = "Hello")
test_label.pack()
root.mainloop()
I can only run this python code from the IDLE, if I run it any other way the window flashes on the screen and closes immediately. I've tried:
-adding an "input" line to keep it from closing
-running from the windows powershell
-compiling the code into an EXE with pyinstaller
and now I can't find any other suggestions. I tried making a simple 1-line program that just asks for input, and that works normally and stays open fine. The tkinter program works fine in IDLE but not any other circumstance.
What's happening here?
EDIT: If I run the program from the command line instead of windows 10 powershell, I get the following output:
Traceback (most recent call last):
File "C:\Users\Cam\Desktop\CSCI Notes\Programs\test.py", line 1, in
<module>
import tkinter
ImportError: No module named tkinter
However, the tkinter file is in the python library on my computer, and importing tkinter in python shell or IDLE works fine.
When I run python on command prompt, it shows python 2.7, so I changed tkinter to Tkinter and the program worked by importing the .py file
Using cmd:
Pyinstaller works(through canopy cmd prompt):
the first line is what I put into my IDLE's cmd prompt
Which populates the folder when executed:
And inside dist, I run test.exe which shows the window
NOTE: my system command prompt is using python 2.7 while the canopy(python environment) command prompt uses 3.5 with pyinstaller
Okay, I think I've solved this one! I read that windows can sometimes try to open .py files with python 2.7 instead, even if they're written in 3.6. I uninstalled python 2.7 from my computer, and now the file runs normally.
So for anybody having this problem, try to make sure your computer is opening python 3, not python 2.
I have also had this problem and as far as I can see no one has a proper solution.
The best I have found is putting -i before your filename. For example:
python -i yourfile.py
this will start the IDLE in the command line
This could also happen if you are using a modulo that isn't installed in your computer even if you have installed it using your IDLE. Try installing it with the command "pip install modulo" else try installing it manually.
When i type import pygame, i get an error that reads:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
File "C:\Python27\lib\site-packages\pygame\__init__.py", line 95, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
>>>
Does anybody know what this means?
It means that you need to look at pygame\base.pyd in Dependency Walker and see which DLL it can't find.
I made this mistake too. The problem is that you are using the Idle Shell to attempt to build a Python program. Here is how I get out of the shell:
Save the Idle Shell as a .py in a location of your choice
Afterward, find the .py you created.
Left click, then Right click to display the context submenu (the menu with copy/paste)
Select "Edit with Idle"
This will open the .py file in the Editor Window. Delete all extra content to create a blank screen
Now you can import your modules and begin programming:
import os, sys
import pygame
from pygame.locals import *
[...]
This will give you the head start to work with pygame.
This question at Game Developement (another Stack Exchange Site) should answer your question:
Installing the right version of PyGame
This user can't make Python to know that PyGame is there so he asks that question. His question should be similar to yours, making it convinient for you. I hope this helps you!
In the command prompt, write pip install pygame if you have a Windows PC, or pip3 install pygame if you have Linux or MacOS.