I usually use sublime to run my code, but when I try to use the interpreter (both in cmd and powershell) it opens python and then immediately exits without any input from me.
eg:
PS C:\Users\Lahoa\Documents> python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
PS C:\Users\Lahoa\Documents>
As you can see it opens python(successfully), then exits without me being able to do anything. Has anyone seen this before? When I google I only find help regarding running scripts that close automatically on finish...
Thank you for any input
I found a solution. We have a script that adds various paths for various extra packages at my work. I found an error in one of the imports, which caused python to fail but wasnt giving an error message due to a try statement in the script.
Related
I like Python. I like IDLE. I use python and IDLE to teach programming to to sighted and non-sighted people. There are other python programming/learning interfaces available e.g. Eclipse with PyDev plugin, pyCharm. I use IDLE rather than others because my students only have to download one thing - Python which includes, among other things, IDLE, Turtle, Tkinter. For the beginner, I want to keep the impediments to a absolute minimum.
My blind students' problem with IDLE is that execution output is not spoken:
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
2+2
4
The "4" is not spoken.
For clarificaion:
My students use the JAWS program which catches text and the text is translated into spoken sounds. IDLE's program output is not spoken.
Our workaround for interactive python is to use python directly. Example:
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 2+2
4
>>>
In which the "4", as well as the other text, is spoken.
I might be missing something. If so please let me know. As it is, we use python directly for interactive work and IDLE to do file based programs.
To verbalize the program's output we have to select and copy the output window's text, switch to a Notepad program window and paste the results which are then spoken.
Even program editing, in a IDLE file window is difficult for my blind students. They currently prefer to, from the IDLE file window, select, copy, switch to Notepad, paste, make edits, select, copy, switch to IDLE file window, select ALL(to enable overwriting the old contents), paste, then run the program. Even so, IDLE is still useful for program development.
I'n new to django and I'm practicing through Django's Documentation on setting up my first project.
All worked well until it asked to invoke the Python shell with the command python manage.py shell
As a result, nothing really happens apart from showing the following text:
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
Could someone please help? I tried finding an answer in very different sources but no one has really answered it. Thank you in advance.
That is what exactly happens. Just start typing in shell you can see the result.
Do not expect any other screen to open.
If you want to exit from shell use exit() command.
I hope that helps.
Thank you.
The python manage.py shell command opens an interactive shell (using IPython or bpython if available). It's used to run code with the django environment enabled. This means that if, for example, you want to try out some database queries you could:
>> from yourproject.yourapp.models import YourModel
>> YourModel.objects.all()
>> [<YourModel: 1>]
I'm using Windows 7 64 bit and Python 3.7.1 (Anaconda) takes more and more memory after each execution to grab the interactive mode.
Symptoms
If I execute the following line :
> python -c "print('ok')"
It will run without any problems almost immediately.
Now if I run python directly :
> python
It first display the following :
Python 3.7.1 (default, Oct 28 2018, 08:39:03) [MSC v.1912 64 bit (AMD64)] :: Anaconda custom (64-bit) on win32
Type "help", "copyright", "credits" or "license" for more information.
And then start to load...
First time I noticed that python was more and more slow to access the interactive mode he needed already few seconds. Now, it can be at least 2 minutes to execute :/ and it is using more and more memory > 3.0 Go !
I did some search but didn't find anything about that problem. Does someone has an idea on how I could figure out what's going on ?
Edit
I was able to get the interactive mode at once by doing
> python -S
Thank to #snakecharmerb. I had to retrieve my .python_history file located for me at C:/Users/Administrator and delete it.
.python_history was huge : Almost 100 Mo and it's content was unreadable :
¢Ã¢â€šÂ¬Ã‚¦Ãƒâ€šÃ‚¡ÃƒÆ’ƒâ€šÃ‚¢ÃƒÆ’ƒÂÂÂÃ
I just started learning python. I created a simple .py file using the IDLE editor and I am trying to run it from the command prompt. However, every time it keeps giving me the "SyntaxError: Invalid Syntax" message.
This is how the .py file looks when opened with notepad:
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sys
>>> print(sys.platform)
win32
>>> x="Spam!"
>>> print(x*8)
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
>>> print(2**100)
1267650600228229401496703205376
>>>
And this is what I type in the cmd:
C:\code\script1.py
Assistance would be appreciated.
That's not a Python program, it's the log of an interactive (command prompt) session.
Instead, try entering the following in any text editor (e.g. notepad, notepad++), save it as C:\code\script2.py and then run it as you did:
import sys
print(sys.platform)
x="Spam!"
print(x*8)
print(2**100)
[EDIT]
If you want to use Idle for this, click [File][New] to create a Python source code file, type in the above, save it and then run it as you did.
[EDIT2]
Idle is and example of an Interactive Development Environment (IDE). Since you're new to programming: IDE's tend to obscure what's going on, although Idle isn't a severe case of this. So using a separate editor and running from the command line as you did is actually a good way to familiarize yourself with what's going on under the hood. This will pay off in many ways in the long run.
As said before; This is not a python file...
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
That's the shell (which you get if you just type: python) where you can type commands like:
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
and this will instantly execute...
What you need to to is go on and create a script.py file, write your stuff in there and then execute it as: python script.py
Greeting Elias
Steps to repeat:
gfixler#gigabox:/autodesk/maya2012-x64/bin$ ./mayapy
Python 2.6.4 (r264:75706, Nov 3 2009, 14:09:42)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import maya.standalone
>>> maya.standalone.initialize() # this hangs until I ^C
^CResult: untitled
Fatal Error. Attempting to save in /usr/tmp/gfixler.20120908.1953.ma
gfixler#gigabox:/autodesk/maya2012-x64/bin$
I think it's a library path issue of some sort, but I don't know how to find out.
I figured out the issue.
In trying to solve this I learned about python -m trace --trace script.py, and also a bit about pdb, a Python debugger. I tied these together by calling a trace on a file containing this:
pdb.run(maya.standalone.initialize(), globals(), locals())
I don't know if that was using either incorrectly, or overkill (trace alone was hanging after printing out a tremendous amount of information, which redirected into a file yielded nothing useful), but after hitting n (next) and s (step) followed by hundreds of enter keypresses in pdb got me nowhere, on a whim I typed help and got a help menu. I decided to try the listed EOF command, and it ran until it crashed with a message about being unable to load the commandPort. I remembered I set that value to autoload (Preferences window, Applications section) last week while fighting with nose, and apparently that was causing it to hang on a bad entry (":12345"), with absolutely no messages about anything. I opened UI Maya, deleted that preference, and now mayapy initializes fine. Phwew.