Download Python Source Code
First, obtain the target source archive from the official Python releases page. Stable builds are listed on the left, pre-releases on the right; we’ll use Python 3.8.18 for this walkthrough. Click the "Gzipped source tarball" link to save locally—alternatively, pull directly to your server with wget if bandwidth is sufficient.
Transfer the archive to your Linux cloud instance (via a control panel such as Baota, SFTP/SCP, etc.). We’ll place it in /root/apps/dependencies for organization; create this directory first with mkdir -p /root/apps/dependencies if it doesn’t exist. Extract the tarball using tar -xzf Python-3.8.18.tgz or via your control panel’s right-click extract function.
Compile and Install Python
Open a terminal session (either through your control panel or a direct SSH connection). Navigate to the extracted source directory, configure the build with a custom prefix to avoid overwriting the system Python, compile, and install:
cd /root/apps/dependencies/Python-3.8.18
./configure --enable-optimizations --prefix=/usr/local/python38
make -j$(nproc)
sudo make altinstall
The --enable-optimizations flag speeds up Python execution slightly (adds ~10 minutes to compilation), and make altinstall ensures we don’t replace system-critical python3/pip3 symlinks.
After installation, verify success by checking the version directly at the custom path:
/usr/local/python38/bin/python3.8 --version
/usr/local/python38/bin/pip3.8 --version
Configure Accessibility
We’ll set up symlinks to make this Python version easy to invoke globally without conflicting with system tools. Use python3.8 and pip3.8 as the global command names to avoid overwriting existing ones:
sudo ln -sf /usr/local/python38/bin/python3.8 /usr/bin/python3.8
sudo ln -sf /usr/local/python38/bin/pip3.8 /usr/bin/pip3.8
Set Up a Fast PyPI Mirror
Create a user-level pip configuration directory and file to use a domestic mirror (or your preferred alternative):
mkdir -p ~/.config/pip
nano ~/.config/pip/pip.conf
Paste the following into pip.conf, save with Ctrl+O and exit with Ctrl+X:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
Install Common Packages
Let’s add poetry for virtual environment and dependency management, requests for HTTP interactions, and numpy for numerical operations:
pip3.8 install poetry requests numpy
Practical Mini App: Secure Memorable Passphrase Generator
Generate passphrases using a modified Diceware-style approach with word groups and optional special characters/numbers. This avoids completely random strings that are hard to remember.
First, fetch a lightweight word list (we’ll use a shortened version for demonstration, stored as a Python list for portability):
import random
import string
# Shortened curated word list (replace with full Diceware list for security)
CURATED_WORDS = [
"apple", "zebra", "moon", "forest", "coffee", "mountain", "cloud", "book",
"piano", "robot", "garden", "star", "river", "chair", "laptop", "rainbow"
]
def generate_passphrase(min_words=4, max_words=6, add_special=True, add_number=True):
"""Generate a secure, memorable passphrase."""
# Select random number of words within range
word_count = random.randint(min_words, max_words)
pass_parts = random.choices(CURATED_WORDS, k=word_count)
# Capitalize first letter of each word (optional but adds entropy)
pass_parts = [word.capitalize() for word in pass_parts]
# Join with random separator (avoids predictability)
separators = ["_", "-", "."]
if add_special:
separators += list(string.punctuation.replace("_", "").replace("-", "").replace(".", ""))
sep = random.choice(separators)
passphrase = sep.join(pass_parts)
# Add number at random position if enabled
if add_number:
num_pos = random.randint(0, len(passphrase))
passphrase = passphrase[:num_pos] + str(random.randint(0,9)) + passphrase[num_pos:]
return passphrase
if __name__ == "__main__":
while True:
try:
min_w = int(input("Enter minimum number of passphrase words (3-10): "))
max_w = int(input("Enter maximum number of passphrase words (3-10, >= min): "))
if not (3 <= min_w <= max_w <=10):
print("Error: Min/max must be between 3-10 and max >= min!")
continue
spec = input("Include special characters? (y/n): ").strip().lower() == 'y'
num = input("Include a random number? (y/n): ").strip().lower() == 'y'
result = generate_passphrase(min_w, max_w, spec, num)
print(f"\nGenerated Passphrase: {result}")
print("Please store this securely (e.g., password manager)!")
except ValueError:
print("\nError: Please enter valid integers for word counts!")
again = input("\nGenerate another passphrase? (y/n): ").strip().lower()
if again != 'y':
break