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
venv
is similar to Node’snvm
requirements.txt
is similar topackage.json
pip
is similar tonpm/yarn
- Poetry is similar to
yarn/pnpm
with enhanced features likepackage.json
+yarn.lock
combined
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/project
as 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
💡 Tip: Like pwd
in JavaScript projects, you can use pwd
(Unix) or cd
(Windows) to verify your current directory
Installing Developer Tools
💡 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
💡 Tip: .venv
is similar to node_modules
- it should be in your .gitignore
Activating Virtual Environment
💡 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:
Generate requirements.txt
Like npm init
or generating package.json
:
💡 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):
Common Poetry Commands
💡 Tip: poetry.lock
is similar to yarn.lock
or package-lock.json
Running the Application
Streamlit Setup
💡 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):
Quick Tips for JavaScript Developers
-
Package Management:
pip
→npm
requirements.txt
→package.json
poetry
→yarn/pnpm
-
Environment:
.venv
→node_modules
activate
script →nvm use
pip list
→npm list
-
Common Gotchas:
- Always check if virtual environment is activated (look for
.venv
prefix) - Use
python3
instead ofpython
on Unix systems - Remember to deactivate venv when switching projects
- Keep
requirements.txt
orpoetry.lock
in version control (like package.json)
- Always check if virtual environment is activated (look for
-
Development Workflow:
- Use
ruff
for linting (similar to ESLint) - Consider using VS Code with Python extension (similar to JavaScript extensions)
- Set up
.gitignore
to 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