Skip to content

Instantly share code, notes, and snippets.

@uogbuji
Last active August 25, 2023 01:10
Show Gist options
  • Save uogbuji/435d86684894997dc3d8d46da7da1ea9 to your computer and use it in GitHub Desktop.
Save uogbuji/435d86684894997dc3d8d46da7da1ea9 to your computer and use it in GitHub Desktop.
My Python dev setup for Linux (Debian, Ubuntu, Mint & ChromeOS/Crostini)

Python dev environment on Linux

User local install as much as possible, leaving system-wide kit (e.g. python & python-pip .debs) alone. Tested on Debian, Ubuntu, Mint & ChromeOS/Crostini.

Environment

Set up the dev environment (this is the only system-wide part):

sudo apt install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev
#Optionally:
sudo apt install libxml2-dev libxslt1-dev git mercurial

Install Python

mkdir -p $HOME/.local/venv
mkdir -p ~/src
# mkdir -p ~/Downloads # If needed
cd ~/Downloads
wget https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tar.xz
cd ~/src
tar xvf ~/Downloads/Python-3.10*
cd Python-3.10.4
./configure --enable-optimizations --prefix=$HOME/.local
make; make install

Create & activate a virtual envirnment

Create:

export DEVENVTAG=main
$HOME/.local/bin/python3 -m venv $HOME/.local/venv/$DEVENVTAG

You only need to specify the full path to Python when creating the venv, as above.

Activate:

source $HOME/.local/venv/$DEVENVTAG/bin/activate
pip install wheel #Recommended; One time per venv
pip install --upgrade pip #Needed from time to time, to make sure pip itself is up to date

In future you only need the first line above to activate the venv.

Appendix: What's the system Python on Debian, anyway?

First of all you can check whether the Debian version you want has the Python version you want. In April 2022 a query:

https://packages.debian.org/search?keywords=python+3.10

Indicated that the 3.10 version was only in testing and unstable, not in stable (when installed you got 3.10.4).

Stable had Python 3.9 (3.9.2)

https://packages.debian.org/search?keywords=python+3.9

You can install Python 3 and other dev environment bits system-wide

sudo apt install python3 python3-dev python3-venv

Though I still recommend sticking to .local and not mucking with system-level Python versions at all.

@QGB
Copy link

QGB commented Sep 27, 2022

b'ls\r\r\n\r\nPassword: '                                                                                                                         
>>> uart1.read()                                                                                                                                  
>>> uart1.write(b'@@##$$%%\n');uart1.read()                                                                                                       
9                                                                                                                                                 
>>> uart1.read()                                                                                                                                  
b'\r\n\r\nLogin incorrect\r\naml login: '                                                                                                         
>>> uart1.write(b'root\n');uart1.read()                                                                                                           
5                                                                                                                                                 
>>> uart1.read()                                                                                                                                  
b'root\r\nPassword: '                                                                                                                             
>>> uart1.write(b'@@##$$%%\n');uart1.read()                                                                                                       
9                                                                                                                                                 
b'\r\nLogin timed out after 60 seconds.\r\n\r\r\nUbuntu 18.04.6 LTS aml ttyAML0\r\n\r\naml login: '                                               
>>> uart1.write(b'killall htop\n');uart1.read()                                                                                                   
13                                                                                                                                                
b'@@##$$%%\r\r\nPassword: '                                                                                                                       
>>> uart1.write(b'@@##$$%%\n');uart1.read()                                                                                                       
9                                                                                                                                                 
b'\r\n\r\nLogin incorrect\r\naml login: '                                                                                                         
>>> uart1.write(b'root\n');uart1.read()                                                                                                           
5                                                                                                                                                 
b'@@##$$%%\r\nPassword: '                                                                                                                         
>>> uart1.write(b'root\n');uart1.read()                                                                                                           
5                                                                                                                                                 
b'\r\n\r\nLogin incorrect\r\naml login: '                                                                                                         
>>> uart1.read()                                                                                                                                  
b'root\r\nPassword: \r\nLogin timed out after 60 seconds.\r\n\r\r\nUbuntu 18.04.6 LTS aml ttyAML0\r\n\r\naml login: '                             
>>> uart1.write(b'root\r\n');uart1.read()                                                                                                         
6                                                                                                                                                 
>>> uart1.write(b'@@##$$%%\n');uart1.read()                                                                                                       
9                                                                                                                                                 
b'root\r\r\n\r\nPassword: '                                                                                                                       
>>> uart1.read()                                                                                                                                  
b'\r\nLast login: Tue Sep 27 03:42:25 UTC 2022 from 192.168.1.3 on pts/0\r\n \x1b[0;1;34;94m____\x1b[0m  \x1b[0;1;34;94m___\x1b[0m   \x1b[0;1;34;9
4m___\x1b[0m  \x1b[0;34m____\x1b[0m  \r\n\x1b[0;1;34;94m/\x1b[0m \x1b[0;1;34;94m___|/\x1b[0m \x1b[0;34m_\x1b[0m \x1b[0;34m\\\x1b[0m \x1b[0;34m/\x1
b[0m \x1b[0;34m_\x1b[0m \x1b[0;34m\\|\x1b[0m \x1b[0;34m___|\x1b[0m \r\n\x1b[0;34m\\___\x1b[0m \x1b[0;34m\\\x1b[0m \x1b[@aml:~# '                  
>>> uart1.read()                                                                                                                                  
>>> uart1.write(b'killall htop\n');uart1.read()                                                                                                   
13                                                                                                                                                
>>> uart1.read()                                                                                                                                  
b'killall htop\r\nroot@aml:~# '                                                                                                                   
>>> uart1.read()                                                                                                                                  
>>>            

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment