Setting Up a Python Project: A Guide for JavaScript Developers
For JavaScript Developers
Coming from the JavaScript ecosystem, here are some key parallels:
- Python’s
venvis similar to Node’snvm requirements.txtis similar topackage.jsonpipis similar tonpm/yarn- Poetry is similar to
yarn/pnpmwith enhanced features likepackage.json+yarn.lockcombined
Prerequisites and Assumptions
System Requirements
- Python 3.10 or higher installed (like Node.js in JavaScript)
- Base setup tested on Ubuntu 24.04, but instructions work for all major OS
- Terminal access (similar to running npm commands)
Important Assumptions
- All commands assume
/dev/projectas your base path (customize this to your actual project location) - For Windows users, replace
/with\and adjust paths accordingly (e.g.,C:\dev\project) - Project structure exists (similar to having your React/Astro project folder)
- You have necessary permissions (like when you need sudo for global npm installs)
Initial Project Setup
Navigate to Project
# Replace with your actual project pathcd /dev/project
# Windows users:cd C:\dev\project💡 Tip: Like pwd in JavaScript projects, you can use pwd (Unix) or cd (Windows) to verify your current directory
Installing Developer Tools
pip3 install vulture ruff💡 Tip: These are like ESLint/Prettier in JavaScript ecosystem
Virtual Environment Setup
Think of this as creating an isolated environment (similar to using different Node versions per project)
Creating Virtual Environment
# Unix/macOSpython3 -m venv /dev/project/.venv
# Windowspython -m venv C:\dev\project\.venv💡 Tip: .venv is similar to node_modules - it should be in your .gitignore
Activating Virtual Environment
# Unix/macOSsource /dev/project/.venv/bin/activate
# Windows.\.venv\Scripts\activate💡 Tip: You’ll see (.venv) in your terminal, similar to seeing Node version when using nvm
Package Management
Approach 1: Using requirements.txt
Similar to using package.json with fixed versions:
pip3 install -r requirements.txtGenerate requirements.txt
Like npm init or generating package.json:
pip3 install pipreqspipreqs . --force --ignore .venv💡 Tips:
- Check installed packages:
pip3 list(similar tonpm list) - Search for packages:
pip3 search package_name(likenpm search) - View package info:
pip3 show package_name(similar tonpm view) - Check outdated packages:
pip3 list --outdated(likenpm outdated)
Approach 2: Using Poetry
Poetry is more like modern JavaScript package managers (yarn/pnpm):
# Installation# Unix/macOSsudo apt install python3-poetry# orpip3 install poetry
# Windowspip install poetryCommon Poetry Commands
# Like yarn installpoetry install
# Like yarn addpoetry add package-name
# Like yarn removepoetry remove package-name
# Like yarn upgradepoetry update💡 Tip: poetry.lock is similar to yarn.lock or package-lock.json
Running the Application
Streamlit Setup
streamlit run app.py💡 Tip: This is similar to npm start or yarn dev - it starts a development server
Custom Port Configuration
Create .streamlit/config.toml (similar to .env files):
[server]port = 8085Quick Tips for JavaScript Developers
-
Package Management:
pip→npmrequirements.txt→package.jsonpoetry→yarn/pnpm
-
Environment:
.venv→node_modulesactivatescript →nvm usepip list→npm list
-
Common Gotchas:
- Always check if virtual environment is activated (look for
.venvprefix) - Use
python3instead ofpythonon Unix systems - Remember to deactivate venv when switching projects
- Keep
requirements.txtorpoetry.lockin version control (like package.json)
- Always check if virtual environment is activated (look for
-
Development Workflow:
- Use
rufffor linting (similar to ESLint) - Consider using VS Code with Python extension (similar to JavaScript extensions)
- Set up
.gitignoreto exclude.venv(like excludingnode_modules)
- Use
Remember: Python’s package management is more like npm’s older versions - global vs local installations matter, and virtual environments are crucial for project isolation.
For the cleanest experience, treat each Python project like a separate JavaScript project with its own dependencies and environment settings, which e will cover in next blog