Ubuntu 18.04 build Python environment (pycharm + Anaconda)


There are multiple versions of Python in Ubuntu system, so it is inevitable to encounter errors in environment variables when using it, especially when running scripts automatically. Especially in the past month, all of the lab’s partners have been devoted to python. In order to help young people quickly build their own Python environment, the author wrote this tutorial. Of course, if there is no problem with Ubuntu’s own python, you can skip the installation of anaconda.


Anaconda refers to an open source Python distribution, which contains more than 180 science packages such as CONDA, Python and their dependencies. Because it contains a large number of science packages, Anaconda has a large download file (about 531 MB). If you only need some packages, or need to save bandwidth or storage space, you can also use miniconda, a smaller distribution (only including CONDA and python). The above excerpt from Baidu Encyclopedia.

Download Anaconda

We go to Anaconda’s official website to download the installation package of anaconda, and choose according to our own operating system, number of bits and python version used. After getting the file anaconda2-5.2.0-linux-x86_.sh (because the author has installed Python 3, here use Python 2 as an example), open the terminal in the current folder and input the command:

sh Anaconda2-5.2.0-Linux-x86_64.sh

You will enter the anaconda installation interface.

Anaconda installation

At this point, we have entered the command line installation interface:


According to the prompt, just press enter to continue the installation. Next, you will enter a long period of service terms. If you don’t like these long articles like the author, you can click enter all the time to get through this stage quickly:


Until the following prompt appears, operate according to the prompt, accept the terms, type yes at the terminal and press enter:


At this time, Anaconda will let you choose the installation location of anaconda. If you have no comments, you can directly click enter to start the installation, or you can directly enter the installation location you like. Here, I will directly click enter to enter the installation phase:


After confirming the address, click enter again to enter the installation phase, which will lead to a slightly lengthy installation phase. After the installation, you will be asked if you need to configure Anaconda into the environment variable. Just enter yes. Here, the author has already configured the environment variable, so the terminal will skip this phase and go to the last step to install vs code Here, you can fill in yes or no according to your own needs:


At this point, Anaconda has been successfully installed.

Pycharm installation and initial configuration

Pycharm Download

First, go to pycharm official website, or directly enter the website, Download pycharm installation package, and select according to your own computer’s operating system. It is worth mentioning that pycham can be directly searched in the software center of Ubuntu 18.04 and downloaded directly in the software center.


Choose the version you need, insatall will do.

Pycharm installation

Click download on the website, and the compression package of pycharm will be downloaded automatically. After the download is completed, the compressed file can be extracted. Here, the author directly extracts to the current folder:


After decompression, we enter the bin folder in the decompression folder, and enter the following command to start pycharm:

sh pycharm.sh &

In general, this is the command to start pycharm. Pay attention to the folder path.
If there is no special requirement, OK, accept and next are good. Note that accept needs to pull the slider of the terms of use to the end.


The first pycham project

Click create new project to enter the configuration of new project:


It is recommended for beginners to select existing interpreter in project interpreter and choose Anaconda that has been installed or python that comes with the system as interpreter:


Here, the interpreter path of anaconda is python, python2.7 or python3.6 in the bin folder of the installation directory. Click Create after OK.


Right click untitled, select new, and select Python file to create a new py file. Enter the file name, and a python script file will be created successfully. At this time, you can type in

print("hello pycharm!")

To execute the first pysharm file.

There is also a place to be lazy. In the tab tools, there is create desktop entry Option. After selection, pycharm will be added to the software list. Right click pycharm chart in the software center and select Add to favorites to create a shortcut in the system sidebar.

The above is the whole content of this article. I hope it will help you in your study, and I hope you can support developepaer more.