5 Steps : Setup Python Virtual environment in Spyder IDE

Pralhad Teggi
Analytics Vidhya
Published in
4 min readMay 19, 2020

1. Installing virtualenv package with pip

I have setup python 3 environment on my machine. For python 3, Let us install the virtualenv package with pip command as below.

pip install virtualenv

I solved the above error by re-running the same pip command with different options as below :

pip install virtualenv --ignore-installed filelock

2. Creating Virtual Environment for your project

After installing virtualenv, it’s time to create a new environment for our project let’s call it “project-arima-env”

I am working on windows, First let’s move to the directory under which virtual environment directories have to be created.

Now let’s create a virtual environment with name “project-arima-env”

virtualenv project-arima-env

3. Activate your virtual environment

After virtual environment creation, a directory of the same name as your virtual environment name will be created under the directory where you ran the above “virtualenv” command. Now its time to activate your environment.

Under the Scripts directory, there will be an activate batch script as shown in the above figure. Run the activate batch script to activate the virtual environment.

Now my environment “project-arima-env” is activated.

4. Perform actions in your environment

Your new environment is active and you can do whatever you want, go install those crazy python libraries without fear !

I am working on time series modelling in data science and I want to perform the Auto.Arima function in python similar to the R package. To do that, let’s install pyramid-arima in current environment :

The required package is installed in my environment and lets perform time series analysis in Spyder IDE.

5. Configure Spyder for your environment

Spyder is an open-source cross-platform IDE. The Python Spyder IDE is written completely in Python. It is designed by scientists and is exclusively for scientists, data analysts, and engineers. It is also known as the Scientific Python Development IDE and has a huge set of remarkable features which are discussed in this link.

Now I would like to configure our newly created virtual environment with this IDE. To do that, on top menu of the Spyder, click on Tools → Preferences

In the preferences window, select Python interpreter. Now click on “Use the following Python interpreter” radio button.

Provide the path of the python.exe available in the newly created environment. Then click Ok.

Lets test the environment by importing the package which we installed in the previous step. After importing the library, we will use the auto.arima function to find the best model which will fit the chosen dataset. In this example, we have chosen the time-series records of wine sales by Australian wine makers between Jan 1980 — Aug 1994.

The output of the above code is as below. The auto.arima has tried fitting the various models in the range — p=1..3, q=1..3 and d=1. It is also considering seasonal and non-seasonal components.

The final model is chosen as the best one for this dataset.

From these 5 steps, it is clear that we can create multiple virtual environment in python for each type of job. Keep exploring the things.

Thanks for reading ….

--

--

Pralhad Teggi
Analytics Vidhya

Working in Micro Focus, Bangalore, India (14+ Years). Research interests include data science and machine learning.