How to make Python 3 my default Python at command prompt? - python

I have uninstalled Python 2.7 and installed Python 3. But, when I type Python on my command prompt I get this :
"Enthought Canopy Python 2.7.9 ........."
How can I run Python 3 from command line or how can I make it default on my computer? I asked Enthought Canopy help and I was told that I can "have Canopy be your default Python only in a "Canopy Command Prompt". Not sure what it means.
edit : Thanks everyone. As suggested, I had to uninstall everything and install Python again.

Windows selects which executable will be run by searching the directories in-order from the PATH environment variable (source):
The shell now searches each directory specified by the PATH
environment variable, in the order listed, for an executable file
matching the command name. If a match is found, the external command
(the executable file) executes. If no match is found, the shell
reports an error and command processing completes.
You can modify PATH to put your Python 3.4 directory (typically C:\Python43) before your Python 2.7 directory. From Windows 7 and up, you can use where python to confirm which python will be run (first line of the output).

After editing each path and creating a new variable for each python version, be sure to rename the python.exe to a unique one. i.e. "python3x" . then you can call it in the command line as "python3x". I am assuming that the original python installed (2X) retains the python.exe of which when you call "python" in the command line, it will show the 2x version

You can copy python.exe to python3.exe.
If you are using Anaconda, then you will find it in the sub directory of your environment, for intance, c:\Anaconda\envs\myenvironment.

Related

Why does python --version return nothing in the command prompt

I recently installed Python 3.7.9 for a class I am taking. I am able to run python code both through the windows command prompt and Visual Studio 2019. I was making sure everything was set up correctly. However, when i run the command python --version, it just enters a blank line. IS there something im supposed to do after installing python to set up my Command Prompt?
VS code pulls from the specified file path for each python version, so it will work regardless of if python has been added to your PATH.
Does it give you an error when you just type python into your CMD (not inside vs code)?
If it does then you need to add python to your PATH, details for this can be found here:How to add a folder to `Path` environment variable in Windows 10 (with screenshots)
and the folder paths you need are:
%USERPROFILE%\AppData\Local\Programs\Python\Python37\Scripts\
%USERPROFILE%\AppData\Local\Programs\Python\Python37\

Pointing bash to a python installed on windows

I am using Windows 10 and have Python installed. The new update brought bash to windows, but when I call python from inside bash, it refers to the Python installation which came with the bash, not to my Python installed on Windows. So, for example, I can't use the modules which I have already installed on Windows and would have to install them separately on the bash installation.
How can I (and can I?) make bash point to my original Windows Python installation? I see that in /usr/bin I have a lot of links with "python" inside their name, but I am unsure which ones to change, and if changing them to Windows directories would even work because of different executable formats.
As of Windows 10 Insider build #14951, you can now invoke Windows executables from within Bash.
You can do this by explicitly calling the absolute path to an executable (e.g. c:\Windows\System32\notepad.exe), or by adding the executable's path to the bash path (if it isn't already), and just calling, for example, notepad.exe.
Note: Be sure to append the .exe to the name of the executable - this is how Linux knows that you're invoking something foreign and routes the invocation request to the registered handler - WSL in this case.
So, in your case, if you've installed Python 2.7 on Windows at C:\, you might invoke it using a command like this from within bash:
$ /mnt/c/Python2.7/bin/python.exe
(or similar - check you have specified each folder/filename case correctly, etc.)
HTH.
I do not have Windows 10 installed, but I use Babun and I had the same problem. As I read aliases work well in Windows 10 shell so simply add alias in your .bashrc pointing to your Python installation directory:
alias python /mnt/c/Python27/python
You have at least four options:
Specify the complete absolute path to the python executable you want to use.
Define an alias in your .bashrc file
Modify the PATH variable in your .bashrc file to include the location of the python version you wish to use.
Create a symlink in a directory which is already in your PATH.

Run specific python version that is not in PATH

I am working with a remote machine that I am not administrator in it.
This machine has python 2.6.5 installed and also it appears in PATH.
After I asked they installed in the machine also python 2.7.9, but they refuse to add it to PATH.
is there a way I can execute a script from the command line using the newer version?
You can use the full path to where the python executable is located.
Instead of doing:
python C:\path\to\your\py\file
you do:
C:\Python27\python.exe C:\path\to\your\py\file
with the file path placed in quotes if necessary:
C:\Python27\python.exe "C:\path\to\your\py\file"

Run a python script in windows

I have always used a mac to write and run python scripts. However, I have a bunch of files on a PC that I need to run a script on. I have never really used a PC and don't know how to run the script.
If I go to the command program on the PC and type in python, nothing happens. How do I find where the python path is in order to get into the python prompt? Also, once I am in the prompt, is the importing of modules the same as in a Unix system?
Python isn't added to the system environment's PATH variable by default on windows. You have to either add the path to the directory containing the Python.exe file to the PATH variable, or call python explicitly.
This issue has been addressed in the Python documentation:
Python Documentation: # How to run a Python program under windows
Assuming Python is installed, it is usually placed in a folder prefixed with "Python" and the major/minor version. E.g. C:\Python26

How can I get python in the command prompt on Windows?

I have just installed Python on my Windows 7. I thought that after that I will be able to run python on the command prompt but it is not the case. After the installation I also found out that I can run the python command shell. This is nice. But what should I do if I want to save my program in a file and then I want to run this program (in Linux, for example, I typed "python file_name.py" in the command line).
You need to add the python bin directory to your path. Follow the instructions here and add c:\python26\bin to the path (unless you installed python in a non-default location).
Is python.exe in your windows path? Try to look at the PATH environment variable and see if the installation folder of python is listed there.
You need to update your environment variables to include the path to the Python executable.
On XP you can do this by right clicking on "My Computer" -> Properties and then going to the "Advanced" tab.

Categories