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!