[手动选题][tech]: 20221121.0 ️ How to Setup Python Development Environment in Ubuntu and Fedora.md

This commit is contained in:
六开箱 2022-11-26 23:57:37 +08:00
parent b87e40c6df
commit 979d22795d

View File

@ -0,0 +1,142 @@
[#]: subject: "How to Setup Python Development Environment in Ubuntu and Fedora"
[#]: via: "https://www.debugpoint.com/setup-python-environment-ubuntu-fedora/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to Setup Python Development Environment in Ubuntu and Fedora
======
**This article helps you with the basics and steps to setup your Python development environment in Ubuntu and Fedora.**
[Python][1] became popular in the last couple of years due to its powerful libraries, easy syntax, and portability. It is being used currently almost every system across businesses.
So, if you are trying to set up your Python box and wondering how to begin etc., then you are at the right place. Here, I tried to give you some steps to get started.
### Setup Python Development Environment in Ubuntu and Fedora
#### Python Versions
If you are starting up Python development fresh, then it is recommended that you use the latest Python 3.x for your development, as Python 2.x is already out of support. Almost all the leading Linux distributions removed the dependency on Python 2.
If you are running the latest distributions as of today for Fedora or Ubuntu, then you should have Python 3.x already installed and set as the default interpreter. For example, Fedora 37 and Ubuntu 22.04 LTS, which are currently available, have [Python 3.11][2] as the default Python shell.
A quick way to find out what Python version you have is by running the below command from a terminal in both Ubuntu and Fedora.
```
python2
```
```
python3
```
![python3][3]
If you are running earlier versions of Ubuntu or Fedora, then you can install the latest Python 3.x using the below commands:
**Ubuntu**
```
sudo apt install python3
```
**Fedora**
```
sudo dnf install python3
```
Also, run the below command to find out the path of your Python executable in the current system:
```
which python
```
#### Switching Versions as the default interpreter
If your system has multiple Python versions installed 2.x and 3.x and you want to switch between them, it is possible. 
_If you have only one version installed, you can skip this section._
To switch, first, run python from the terminal to find out the default executable path. Ideally, it should be `/usr/bin/python`. Now, run below to find out the symbolic link to the executable.
```
ln -l /usr/bin/python
```
```
lrwxrwxrwx 1 root root .... /usr/bin/pyhton -> python2
```
Now check out the `$PATH` variable to determine the order of path concatenation which the system looks up for executables.
```
echo $PATH
```
![PATH-Variable][4]
As you can see `/usr/local/bin`is preceding the `/usr/bin/` then you can create a soft symbolic link to `python3`. Then your interpreter should pick up the latest Python 3 instead of Python 2 while running the python command. 
```
ls -s /usr/bin/python3 /usr/local/bin/python
```
Now you should logout and log in again to clear any hash entries, or you can run `hash -r` to clear them out.
Now you can run python from the terminal, and you should have the latest Python 3 picked up.
#### Python IDE
An integrated development environment (IDE) helps you write and compile and execute your code. There are [several free Python IDE available][5] such as PyCharm, Eclipse, Eric, etc., which you can use. That would be another write-up on their pros and cons. 
If you download Python from the official [python.org][1] website, Python accompanies a default development environment called IDLE. IDLE is good for starting up your system, and later you can decide to pick any of the best free Python IDE available.
IDLE is not included in Ubuntu and Fedora along with python as default, you have to install it manually. Run the below commands from the terminal to manually install IDLE.
**Ubuntu**
```
sudo apt install idle
```
**Fedora**
```
sudo dnf install python-tools
```
Once installed, you can launch IDLE from the command line idle or search from the application.
![IDLE-environment`][6]
Now, you can use IDLE to start your development. Most of the basic options you can find in the File menu of IDLE.
I hope this guide explains what you should know before starting your Python development. Although this guide is primarily targeted to Ubuntu and Fedora, you can still follow the instructions for all Ubuntu and Fedora-based distributions as well. If you are facing problems with the Python environment setup, let me know in the comment section below. 
[Next:Learn Bash base64 Encode and Decode With Examples][7]
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/setup-python-environment-ubuntu-fedora/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed
[1]: https://www.python.org/
[2]: https://www.debugpoint.com/install-python-3-11-ubuntu/
[3]: https://www.debugpoint.com/wp-content/uploads/2020/06/python3.jpg
[4]: https://www.debugpoint.com/wp-content/uploads/2020/06/PATH-Variable.png
[5]: https://www.debugpoint.com/5-best-python-ide-code-editor/
[6]: https://www.debugpoint.com/wp-content/uploads/2020/06/IDLE-environment.png
[7]: https://www.debugpoint.com/bash-base64-encode-decode/