Python cannot run in console mode - python

I use Anaconda3 installed python on Windows10.
When I run python --version in git-bash, it works.
$ python --version
Python 3.7.3
$ which python
/d/Programs/Anaconda3/python
But when I run python, it output nothing and pending there
$ python
A image may be more clear here.
I can input anything, when press, but nothing happens, just a new line.
$ python
print(1)
Note My issue is different from Python not working in command prompt? which is cannot find the python path.

Try all your commands with $ python3 ... maybe you dont have installed the python 2 version which gets normaly called by $ python ..

I think here has something to do with git-bash GUI. I cannot run it in git-bash, but I can run it in windows cmd.

Related

Runnig Python in Atom on MacBook doesn't work any more

I have installed and set an Atom on my MacBook. I have installed packages like a script, atom-python-run. I have installed the latest python from their official website too. I was able to run python programs in the default terminal with command+F5 without any trouble. Until today. There is a problem while running python in the terminal (command+F5) and in the atom (command+i).
When I run python in the terminal it gives me:
Last login: Thu Mar 24 12:25:50 on ttys000
python /Users/zalezina/.atom/packages/atom-python-run/lib/../cp/main.py --pause -- python /Users/zalezina/Documents/Zinek/Atom/first-project/test.py
zalezina#Uross-MacBook-Air \~ % python /Users/zalezina/.atom/packages/atom-python-run/lib/../cp/main.py --pause -- python /Users/zalezina/Documents/Zinek/Atom/first-project/test.py
zsh: command not found: python
zalezina#Uross-MacBook-Air \~ %
In I run python in the atom it gives me:
Python - test.py:2
Unable to run
python
Did you start Atom from the command line?
atom.
Is it in your PATH?
PATH: /Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I have tried to uninstall Atom and packages and then install them all again, but the same problem is still there.
Can someone please help me to run python in Atom on Mac again?
Try calling python3 instead of just python in the terminal. If that works, you could alias python to python3 by entering this into terminal echo "alias python=/usr/bin/python3" >> ~/.zshrc to alias python to python3. This one has worked for me.

How do I change from Python 3 to Python 2 in VS Code?

I have both Python 3 (C:\Python\Python38\python.exe) and Python 2 (C:\Python\Python27\python.exe) installed on my Windows 10 computer, and I want to use Python 2 for a project in VSCode.
However, when I select my interpreter to Python 2.7.1 32--bit and run my code, it still runs in Python 3. Typing python -V in PowerShell or Python window gives me "Python 3.8.2". Both versions have been added to my PATH variables, so I am not quite sure why selecting Python 2 in the VSCode interpreter menu still gives me Python 3.
Has anyone encountered anything similar?
Can you add print(sys.prefix) to check which python interpreter you are using? The python --version you get in the VSCode is not the python interpreter you are using. Python2 works well in my VSCode.
And if you want to distinguish the python2 and python3 clearly. You can rename the python.exe to python2.exe which under the Python2 installation Folder. Then in the Powershell, you can get python3 through the python command and python2 through the python2 command.

How do I get Atom to run Python3 in the terminal platformio-ide-terminal?

On my terminal, $ which python (~ is my home directory) gives
~/anaconda3/bin/python
However, running the same command when opening Atom on my terminal (with $ atom .) yields
/usr/local/bin/python
My python3 is different to my default python now, but I do have Anaconda's python3 working well on my Terminal.
I have already tried various things:
changing python to python3 in the two instances in ~/.atom/packages/script/lib/grammars/python.coffee as was laid out here
installing atom-runner and changing python to python3 as was shown here
Changed the shebang in my script to #!~/anaconda3/bin/python (note: the ~ is not what I literally have on my script)
Note 1: I did not have to do the second point with Python 2
Note 2: In the same link as above, I did try out atom-python-run and it worked, but I would like to not use hot keys to run Python on the terminal on Atom, I'd rather manually type in python [script].
If it's relevant, I just upgraded to Mojave (Mac OSX 10.14.6) and Python 3 (3.7.4). Of course, I restarted Atom each time I made the changes as well.
My end goal is to run python [script] on the terminal in Atom (with platformio-ide-terminal) where it executes from ~/anaconda3/bin/python. Finally, if I do do ~/anaconda3/bin/python [script], it does work, but I would like a more practical solution.
I forgot to add this before, but when I do try running a script, I get import errors, for example, ImportError: No module named astropy.io, even though I definitely have AstroPy.
You need to activate your virtual environment from the command line. Then run Atom and open your python file. Now hit the F5 or F6 key and your code should run using python 3.x. Where 3.x is however you set up your virtual environment.
To run Python from the terminal in atom, open the terminal and type
python3 script_file
If your virtual environment was set up for python 3.7, then run
python3.7 script_file
To determine what versions you have type which python3 or which phython3,7 or any other version you may have installed.

Mac: How can I use Python 3.7 in my command line in Visual Studio Code?

How can I use Python 3.7 in my command line?
My Python interpreter is active on Python 3.7 and my python.pythonPath is /usr/local/bin/python3, though my Python version in my command line is 2.7. I've already installed Python 3.7 on my mac.
lorenzs-mbp:Python lorenzkort$ python --version
Python 2.7.13
If you open tab "Terminal" in your VSCode then your default python is called (in your case python2).
If you want to use python3.7 try to use following command:
python3 --version
Or just type the full path to the python folder:
/usr/local/bin/python3 yourscript.py
In case you want to change default python interpreter, then follow this accepted anwser: How to set Python's default version to 3.x on OS X?
You should use python3 instead of python for running any commands you want to run then it will use the python3 version interpreter.
Also if you are using pip then use pip3.
Hope this helps.
This gives you a complete guide in setting up Visual Studio code for python
Getting Started with Python in VS Code

Specify which version of Python runs in Automator?

In my terminal and in CodeRunner my Python is updated to 2.7.6 but when I ran a shell script in the OSX Automator I found that it is running 2.7.2
How can I update the Automator Python to 2.7.6 like the rest of my compilers ?
I couldn't specify explicitly which python for it to use.
So, I ran it in bash environment with following command:
$ your/python/path /path/to/your/python/script.py
And make sure first line of your python program contains the path to the python environment you wish to use.
Eg:
#! /usr/local/bin/python

Categories