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.
Related
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 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.
I have a Python script, and I want to execute it up to a certain point, then stop, and keep the interpreter open, so I can see the variables it defines, etc.
I know I could generate an exception, or I could invoke the debugger by running pdb.set_trace(), then stop the debugger, which is what I currently use.
...but is there a command that will just stop the script, as if it had simply reached its end? This would be equivalent to commenting the entire rest of the script (but I would not like doing that), or putting an early return statement in a function.
It seems as if something like this has to exist but I have not found it so far.
Edit: Some more details of my usecase
I'm normally using the regular Python consoles in Spyder. IPython seems like a good thing but ( at least for the version I'm currently on, 2.2.5) some of the normal console's features don't work well in IPython (introspection, auto-completion).
More often than not, my code generates matplotlib figures. In debug mode, those cannot be updated (to my knowledge), which is why I need to get completely out of the script, but not the interpreter).
Another limit of the debugger is that I can't execute loops in it: you can copy/paste the code for a loop into the regular console and have it execute, but that won't work in the debugger (at least in my Spyder version).
If you invoke your program with python -i <script>, the interpreter will remain active after the script ends. raise SystemExit would be the easiest way to force it to end at an arbitrary point.
If you have ipython (highly, highly recommended), you can go to any point in your program and add the following lines
import IPython
IPython.embed()
Once your program reaches that point, the embed command will open up a new IPython shell within that context.
I really like to do that for things where I don't want to go the full pdb route.
If you are using the Python Shell, just press CTRL + C to throw a KeyboardInterrupt. You can then check out the state of the program at the time the exception was throw.
x = 0
while True:
x += 1
Running the script...
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
Traceback (most recent call last):
File "C:/Python27/test.py", line 2, in
while True:
KeyboardInterrupt
>>> x
15822387
I previously thought that was the issue with IPython, but today I tested again, here is what I did:
Run emacs -Q in cmd window
Open a .py file
M-x, then run python-shell-switch-to-shell, RET, and RET. Then I have the Python shell ready
I in put the following code then:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.ion()
>>> plt.plot([1,2,3])
[<matplotlib.lines.Line2D object at 0x03068610>]
>>>
Actually after this, no figure shows up, and the shell is frozen, e.g., when I input:
>>> print("hello")
nothing happened...I haven't tested other plotting tools but matplotlib. I don't know if it is a bug. I've searched for a while, here and though Google, but no luck. My system is: Emacs 24.3 32 bit for Windows, under Windows 7. If others can duplicate same issue as here, I will report this as a bug.
I used IPython as the Python shell by:
C:/Python27/python.exe -i C:/Python27/Scripts/ipython-script.py --pylab
Then, I input figure(); plot([1,2,3]), as expected, the figure popup and freezes. Then I did: C-c C-d which runs comint-send-eof, and the figure actually get updated! But my IPython shell session is also terminated with the following message:
In [6]:
Do you really want to exit ([y]/n)?
Traceback (most recent call last):
File "C:/Python27/Scripts/ipython-script.py", line 9, in <module>
load_entry_point('ipython==0.13.1', 'console_scripts', 'ipython')()
SystemExit
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
Any helpful clue here?!
one solution is:
(setq python-shell-interpreter "C:\\YourPython3Dist\\python.exe"
python-shell-interpreter-args "-i C:\\YourPython3Dist\\Scripts\\ipython3-script.py console --pylab=qt")
The Argument console in the call of ipython-script.py is the important one!
In Python 3 with qt backend it works for me. I don't know how it works with py 2.7. (should be no problem if these arguments are supported for ipytho-script.py)
I think it would take sometime until the problem is fixed. Until some Windows user actually debugs python.el.
Until then, why not try Emacs IPython Notebook? It is a better IPython binding for Emacs. You don't need to use the notebook part. You can think it as a replacement for python shell in python.el. (disclaimer: I am the author)
I'm a newbie programmer so I'll do my best to clearly ask my question. I'm running Python scripts in Mac 10.6.5 and now trying to write and save to a text file (following instructions in HeadsUp Python book). Whenever I hit function+F5 (as instructed) I get the same "invalid syntax" error and Idle highlights the "1" in "Python 3.1.3" of the header. Here's the header to which I'm referring:
Python 3.1.3 (r313:86882M, Nov 30 2010, 09:55:56) [GCC 4.0.1 (Apple Inc. build 5494)] on darwin Type "copyright", "credits" or "license()" for more information.
Extremely frustrating. I've checked and rechecked the code but this doesn't seem to be code related because the "syntax error" is in regards to the header text that posts in every Idle/Python session. Help anyone?
... and Idle highlights the "1" in "Python 3.1.3" of the header ...
Standalone Python scripts used to contain a "header", but that would be just
#!/usr/bin/env python
or, depending on the name of the interpreter maybe
#!/usr/bin/env python3.1
Not sure I understand your question, though.
you are writing your script in the wrong IDLE window ! when starting IDLE, it opens 2 windows: one for writing a script and another one with an interactive python shell. executing the content of the interactive python shell makes no sense.
#squashua: I have the same issue when I try to run the code either in IDLE or Ubuntu terminal.
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25)
it highlights "5" as syntax error.