Python shell is not restarting after running a module - python

For some reason my python shell is not restarting when I run a module. I feel like I've tried everything. I have opened, and created new files through the shell. I have reinstalled python. I have restarted my machine. etc. etc.
The shell does work when I write a function directly into it, so it's not a problem with the shell itself. When I "run module" in a .py file, it toggles to the shell but it doesn't have the "restart" message as it did before. So, running functions in .py files obviously doesn't work...
Has anyone else experienced this? Any ideas?
I'm using the python 3.4.6 shell for windows 64 bit...I was using 3.4.3 before but I thought upgrading might help.
Thanks in advance

I have personally never experienced this, however, if this has been happening AS SOON AS you upgraded to the 3.4.6 python shell, the existing scripts may be affecting the .py scripts used to run the python shell. I don't know if this helps but maybe go back to 3.4.3 or download the 3.6.4 version of python.
https://www.python.org/downloads/

Related

Why is py.exe using an older version of Python when double-clicking?

I usually run my scripts in a command prompt, but I tried double-clicking it to use the Python launcher in order to test something. Weirdly, I've discovered that while doing py script.py in the command prompt will run the script under the version I want, 3.10, if I were to double-click the file it will run it with 3.8, my old version.
I don't think I need to keep Python 3.8 anymore and I can probably just uninstall it and solve this, but before I do I'm curious as to why this is even happening in the first place, and is there a way I can change what version its using?
EDIT: Here's a short gif to show it clearly. From what I can tell, I think when I run py in the command prompt its using the path to C:\Windows\py.exe, but when I double-click its opening with C:\Users\Seth\AppData\Local\Programs\Python\Launcher\py.exe. I'm still not really sure how to make it use the right one though, even if I remove the latter from my PATH it does the same thing.
If you are using updated pip so that time it's need that python version or if you have made py into exe with any version basically it depends on that one also otherwise it will work simply.
Hope this will help you.

running Python 3.9.12 on Pycharm

I have Python 3.9.12 installed on my linux machine at the moment, and it is working fine when I launch a terminal and run a python file. However when I try to do the same in Pycharm, the code does not work properly because the Interpreter is still 3.9.9. Any ideas how I can upgrade the interpreter? I tried to install Conda which has version 3.10, however I cannot seem to be able to attach this interpreter to run my code.
Any help is very much appreciated!
Thank you!
In order to navigate to your options quickly, use CTRL+SHIFT+A, which yields a search bar. When typing in python interpreter it will navigate you to the interpreter settings of PyCharm. When clicking on the settings cog of the defined interpreter, you can select Add.... Select that and you can configure your new interpreter. Please note that you must know where the executable is of the interpreter. If you are unsure, you can use:
import sys
print(sys.executable)

Can no longer access debugger in BBEdit virtual environment on MacOS Catalina

I upgraded to Catalina today, which required updating BBEdit as well. Now I am having trouble using my virtual environment, specifically the debugger in BBEdit.
I installed python3 in a virtual environment via Homebrew, set the correct path, and can access the virtualenv correctly via:
cd /Users/joecat/venvjc
source /Users/joecat/venvjc/bin/activate
I used pip3 to install modules needed
I am trying to run this test script:
#!/Users/joecat/venvjc/bin/python3
import pandas
print('hi')
The pandas module is only in the virtual environment so it should work. If I "Run in Terminal" through BBEdit, the code executes:
But when I try to run in debugger via Command+D, the code executes without the "pdb" debugger popping up at all:
Then, if I adjust the first line to be a "fake" path (assuming this just skips it) it correctly opens up the debugger, and pandas can't be imported because it's no longer using the virtualenv, which is correct:
#!/Users/joecat/venvdddddjc/bin/python3
import pandas
print('hi')
What am I doing wrong with respect to changes to Catalina/BBEdit? I switched to using zsh over bash... is that part of the problem? I am a newbie and happy to provide more details if needed. Thanks for any help anyone can provide.
There have been a lot of changes over time to how BBEdit interacts with the shell environment. As of 13.0.4, BBEdit will run your login shell to capture its environment, whenever you run a #! script. But there are special cases for Python, Ruby, and Perl, since those all have built-in support in BBEdit.
One thing to be aware of: if you've switched to zsh from bash, a common practice is to copy your bash environment from .bash_profile to .zshrc. This won't work correctly in BBEdit, because the shell that BBEdit runs is not an interactive shell.
For that reason, you should set up the majority (and perhaps all) of your zsh environment by putting the declarations (PATH, etc) in either .zprofile or .zshenv (but not both). Any interactive stuff can remain in .zshrc.
(And if you're still stuck, writing to support#barebones.com is always a good idea.)
(p.s. I would not recommend using any BBEdit version older than 13.0.4 on Catalina.)
I was able to correct the issue by downgrading to BBEdit 12.1.16, the earliest release that works with Catalina, as opposed to the latest version 13.0.2 that I was using.
This may be a bug in BBEdit, or else there's something else that changed this functionality between 12 and 13.
Would love to learn more if anyone has any information on this issue. Google is turning up next to nothing on this problem
In case it is helpful to anyone who comes across this issue, I was able to resolve this by importing and setting trace on the pdb module in lines 2 and 3 (right after the virtual environment path set on line 1):
import pdb
pdb.set_trace()
This allows the debugger to run normally in BBEdit 14.1.2, macOS Monterey 12.3.1.
No idea what the underlying issue is. I guess pdb is naturally imported when using the native OS python, but must be manually imported when using a virtual environment.
Hope this helps.

Getting Enthought Python IDLE to run code when shell is restarted

I'm running EPD and using IDLE for most of my coding. What I'd like to do is get IDLE to run a script to customize my environment whenever I restart the Python shell. I've tried reading all the various posts on customizing IDLE and the Python environment, and I've yet to see anything that addresses this specific scenario. Does IDLE or EPD IDLE (if there's any difference) have a particular module it's looking for when it restarts the shell, like usercustomize.py or sitecustomize.py? Has anyone accomplished this on their own? Any guidance is appreciated.
Upon startup with the -s option, IDLE will execute the file referenced by the environment variables IDLESTARTUP or PYTHONSTARTUP.
Check out: http://docs.python.org/library/idle.html#startup
Cheers,
Johannes

How can I run a python script on windows?

Can anyone please tell me an IDE for running python programs? Is it possible to run the program through command line?
Take a look at ActiveState's ActivePython. It's quite a nice implementation of Python on Windows. Another way is using Cygwin's Python port. These two are Python implementations. I don't use an IDE, I write my Python code in Notepad++.
To run a python program after saving it to C:\Users\vaibhav\Code\myscript.py:
ActivePython: If I remember right, ActiveState updates the path correctly. So it should be a s simple as:
Press "start" in the task bar
In the search field search for "cmd"
In the appearing box navigate to your folder with the python script: dir Users\vaibhav\Code
call python myscript.py and you're done
Cygwin: After installing Cygwin, you have a full-featured bash terminal on your Windows machine.
click on the Cygwin icon on your desktop
In the appearing window navigate to the folder with your python script: cd /cygdrive/c/Users/vaibhav/Code
type python myscript.py
e voila
IDE for running scripts? You can have any IDE you like, but if you need only to run python scripts you go like this:
python.exe pythonScript.py
I like the EasyEclipse for python distribution. You'd need to have python and java installed of course.
PyDev and Komodo Edit are 2 nice Python IDE on Windows.
I also like the SciTE text editor very much.
These 3 solutions make possible to run Python scripts
I tried to run a Python script with multiprocessing on windows. see this tutorial
It does not work on Windows, but on raspian it went very well. Thus I knew that it was a Windows problem. I installed cygwin and followed this tutorial Installing Python inside Cygwin.
After that I additionally installed numpy with the command easy_install numpy and now i can run python scripts with multiprocessing on windows (from cygwin).

Categories