Working On A GeoSpatial File in a Python Virtual Environment

Python Virtual Environment allows a user to have an isolated working environment for a specific project. The user can choose a specific version of a library without affecting the other programs. This is going to be useful especially when working on a project that requires libraries that are not at all being used at all times. Also, the user can deactivate and remove environment including its installations easily.

When dealing with GeoSpatial Files such as shape files, GeoJSON, there is a need for GeoPandas. It is a python library that supports spatial data frames.

GeoPandas have many dependencies and directly installing them on the base (root) will definitely affect other python project. So I created a virtual environment for my shape file project.

Here are the steps on how I created new virtual environment in Anaconda:

  1. Open Anaconda Command Prompt
  2. Create new environment
  • conda create -n name_of_env #in this case, I used geo_env2
  • conda activate name_of_env

3. Add the packages you need

  • conda config — env — add channels conda-forge
  • conda config — env — set channel_priority strict
  • conda install python=3 geopandas

4. Install your preferred notebook and or IDE

  • conda install jupyter
  • conda install spyder

5. Open Anaconda Navigator

6. Select the newly created environment

You can now use your new environment for your new project. If after finishing the project, you no longer need the virtual environment, it can be easily removed in Anaconda Command Prompt.

  • conda deactivate
  • conda remove -n name_of_env --all

Licensed Electronics Engineer | Aspiring Data Scientist | a little bit stuck in the MiddlE | the name is an oxymoron