Skip to content

allenchengf/monthly-report-crawler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monthly Report Crawler

Install Python 3.9 on Ubuntu 20.04

Step 1 – Install Required Dependencies

Before starting, it is recommended to update the APT packages cache to the latest version. You can update them by running the following command:

apt-get update -y

Next, you will need to install some packages required to install Python 3.9. Run the following command to install all dependencies:
apt-get install software-properties-common apt-transport-https gnupg2 -y

Step 2 – Install Python 3.9

By default, Python version 3.9 is not available in the Ubuntu standard repository. So you will need to add the dead snakes PPA to your system

Run the following command to add the dead snakes PPA to your system:

add-apt-repository ppa:deadsnakes/ppa

Once the repository is added, update the repository cache and install the Python 3.9 with the following command:
apt-get update -y
apt-get install python3.9 -y

Once Python 3.9 has been installed, you can verify the installed version of Python using the command below:
python3.9 --version
#output Python 3.9.1

Step 3 – Set the Default Python Version

If an older version of Python3.8 is already installed in your system then you will need to set your default Python version to Python 3.9.

First, check the default Python version using the following command:

python3 --version
#output Python 3.8.10

The above output indicates that you have multiple version of Python in your system.

You can also check all Python versions in your system using the following command:
ls /usr/bin/python*
#output /usr/bin/python3  /usr/bin/python3.8  /usr/bin/python3.9

Next, you will need to update your update-alternatives before setting the default Python version. You can update it with the following command:
update-alternatives --install /usr/bin/python3 python /usr/bin/python3.9 1
update-alternatives --install /usr/bin/python3 python /usr/bin/python3.8 2

Next, verify whether both versions are updated or not with the following command:
update-alternatives --list python
#output /usr/bin/python3.8
#output /usr/bin/python3.9

Next, set your default Python version to 3.9 using the following command:
update-alternatives --config python

You will be asked to set the default Python version as shown below:
Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.8   2         auto mode
  1            /usr/bin/python3.8   2         manual mode
  2            /usr/bin/python3.9   1         manual mode
 
Press  to keep the current choice[*], or type selection number: 2

Type 2 and press Enter to set the default Python version. You should get the following output:

update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python (python) in manual mode

Now, you can verify your default Python version using the following command:
python3 --version
# output Python 3.9.1

Step 4 – Fix pip and disutils errors

Fix Python3-apt

Running pip in terminal will not work, as the current pip is not compatible with Python3.10 and python3-apt will be broken, that will generate an error like

Traceback (most recent call last):   
    File "/usr/lib/command-not-found", line 28, in <module>     
        from CommandNotFound import CommandNotFound   
    File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>     
        from CommandNotFound.db.db import SqliteDatabase   
    File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>     
        import apt_pkg ModuleNotFoundError: No module named 'apt_pkg'

To fix this first remove the current version of python3-apt by running
apt remove --purge python3-apt

Then do some cleanup
apt autoclean

Finally, reinstall python3-apt by running
apt install python3-apt

Step 5 – Install pip & distutils

apt install python3.9-distutils

install pip by running
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py
pip
#output pip --version

Install Poetry

curl -sSL https://install.python-poetry.org | python3 -
vim ~/.bashrc
export PATH="/root/.local/bin:$PATH"
source ~/.bashrc
poetry --version
#output Poetry (version 1.3.2)

Install Monthly Report Crawler Project

Step 1 - git clone repo

git clone repo

cd /home/readmin/
git clone http://172.31.251.105/backend/monthly-report-crawler.git

Step 2 - Init Poetry Project

Modify poetry config

poetry config virtualenvs.in-project true

Create virtual env

poetry env use python3.9

Install package

poetry install

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors