I want to run a Python 3 script.
I have looked in the official doc and FAQ, and they are the typical loss. I was looking for answers, I ended up with more questions.
I have Windows and Linux. On Windows, I don't have Python. On Linux, I have Python, but it is Python 2.6.8. I have tried to run my script with this Python, but this gives an error.
I want something simple : a Python 3 that I would put somewhere in my disk and that I would use to run my script. Where can I find this ?
I am looking for a solution for Windows or Linux.
Thank you.
44 Answers
You have registered for Ask Ubuntu Q&A, so I'll provide the command for Ubuntu. In Ubuntu open the terminal and type:
sudo apt install python3 idle3 ipython3 python3 is already installed by default in Ubuntu, I have added python3 to the command for the sake of generality with other Linux distributions. IDLE 3 is an Integrated Development Environment for Python 3. Open IDLE 3 and then open your Python script from the menu in IDLE 3 -> File -> Open.
In Windows IDLE 3 is bundled with the Python 3 installation file, and the instructions for opening a Python 3 script in IDLE 3 are the same.
Try both Idle and IPython and see which one you like. I prefer IPython because it's easier to use than Idle. IPython also runs inside Spyder IDE which is convenient for displaying plots and charts inline in the same pane as the code.
You can also install Python 3 in Windows as a portable app. Portable Python is pre-configured to run directly on the Windows OS from any USB storage device, enabling you to have, at any time, a portable programming environment. Portable Python is available for both Python 2 and Python 3. The download options for Portable Python offer you a choice of downloading optional additional Python packages for scientific computing, etc. The installed size of Portable Python (Python 3), based on the selected packages, is between 63MB and 260MB.
6On many systems, "python" defaults to "python2", but you can run a script under python 3 simply by doing
python3 myscript.pyIssuing
which python3will tell you if that's going to work.
Also, if the script includes an appropriate shebang,
./myscript.pyis supposed to work...
3For Windows:
- You need to install Python 3 from here
- Follow the setup instructions, making sure to check the box that says whether to add it to the system PATH variable
- Go into
cmd,cdto the location of the script, and typepython script.py, replacingscriptwith your filename or open the script with Python Launcher which will have been installed via the installer
To make the script, you can use Python IDLE which was also installed.
4There is a difference from Linux to Windows. On Linux you would type like this:
python3 script.pyWhile on Windows (once you have Python installed) chances are you would type:
py -3 script.pyComparing to py -2 script.py that would run Python 2.
Note: On Windows python or python.exe would call the latest version of Python you have installed.