🌐 What is a virtual environment?
A virtual environment is a special directory for holding a specific version of Python and other modules.
🤔 Why do we need them?
Creating a virtual environment prevents packages with different versions from interfering with each other. This prevents the dependencies from causing conflict issues that stop the app from operating smoothly.
🔄 Types of virtual environments
venv - an inbuilt virtual environment tool from Python
pipenv - the combination of pip and venv
conda - an open-source tool for virtual environments (widely used for data science projects)
Let's explore how to create a virtual environment using conda:
🚀 Setting up your virtual environment
1. Install conda 💻
You can download and install conda from the official Anaconda or Miniconda website
2. Navigate to a directory of your choice in the terminal 📂
cd replace_this_with_your_directory_here
3. Create the Conda environment file 📜
Create a new file and name it (this one is called my_first_conda_venv.yml).
Then add the information about the environment to it:
name: my_first_conda_venv channels: - defaults dependencies: - python=3.10 - pip - pip: - -r requirements.txt
4. Create the requirements.txt file 📝
List the Python libraries you need later on into the requirements.txt file:
pandas numpy matplotlib seaborn sqlalchemy psycopg2 jupyterlab
5. Create and activate your environment 🌿
Use these commands to set up and access your environment:
conda env create -f my_first_conda_venv.yml conda activate my_first_conda_venv
6. Deactivate your environment 🛑
Always shut down the environment after you're done working in it:
conda deactivate
Happy coding!✨
评论
发表评论