Basic Python Commands Cheat Sheet
πΉ Virtual Environment Commands
Section titled βπΉ Virtual Environment Commandsβpython -m venv myenv # Create a virtual environmentmyenv\Scripts\activate # Activate the virtual environment (Windows CMD)myenv\Scripts\Activate.ps1 # Activate in PowerShellsource myenv/bin/activate # Activate in macOS/Linux
deactivate # Deactivate the virtual environmentπΉ Running Python Files
Section titled βπΉ Running Python Filesβpython myscript.py # Run a Python scriptpython -i myscript.py # Run a script and enter interactive mode after executionπΉ pip (Python Package Manager) Commands
Section titled βπΉ pip (Python Package Manager) Commandsβpip install package_name # Install a packagepip install requests numpy pandas # Install multiple packagespip install -r requirements.txt # Install packages from a filepip list # List installed packagespip freeze # Show installed packages in a format usable for a requirements filepip freeze > requirements.txt # Save installed packages to a filepip uninstall package_name # Uninstall a packagepip show package_name # Show details about an installed packageπΉ Checking Python & pip Versions
Section titled βπΉ Checking Python & pip Versionsβpython --version # Check Python versionpip --version # Check pip versionπΉ Python Interactive Shell
Section titled βπΉ Python Interactive Shellβpython # Open Python interactive shellexit() # Exit the Python shellπΉ Python Package Configuration (pip)
Section titled βπΉ Python Package Configuration (pip)βpip config set global.index-url https://your-private-repo-url/ # Set custom repositorypip config set global.trusted-host your-private-repo-url # Set trusted hostpip config set global.timeout 60 # Set global timeout for pip operationsπΉ Miscellaneous Python Commands
Section titled βπΉ Miscellaneous Python Commandsβpython -m http.server 8000 # Start a simple HTTP server on port 8000python -m site # Show Python site-packages locationspython -m ensurepip # Ensure pip is installedπ Conclusion
Section titled βπ ConclusionβThis cheat sheet provides essential Python commands for virtual environments, running scripts, package management, and system utilities. Keep it handy for quick reference and efficient Python development!