Skip to main content

04 - Creating a Virtual Environment

Creating a Virtual Environment

TLDR: A virtual environment is used to create an isolated folder that contains the necessary executables and packages that our project would require.


Before we start coding, let’s define our pipeline system’s folder structure:


First, we clone the Piper git repository in the "/vfxpiper" directory:
PS C:\vfxpiper> git clone git@gitlab.com:vikmpetrov/piper.git
Alternatively, we could have manually downloaded the Piper archived repository and extracted it in the Piper installation directory.

We need and a virtual environment to run our code in, so that our Python interpreter and all the modules and packages we install will be isolated and will remain specific to the Piper development environment. This way we can avoid any conflicts with any other Python versions and packages that have been installed globally on our operating system. We would also have a much easier time testing and deploying our pipeline system with all of its dependencies neatly organized in a single virtual environment.

I'll do my best to avoid any operating system-specific syntax for using the terminal to set up a virtual environment, but the key steps required are:
  • Making sure you have virtualenv for Python3.4 installed; 
  • Navigating to the Piper installation directory; 
  • Using the virtualenv command to initialize a virtual environment;
(Example in Windows PowerShell)
PS C:\vfxpiper> C:\Python34\python.exe -m pip install virtualenv (getting virtualenv for Python3.4.)
PS C:\vfxpiper> virtualenv venv (initializing the virtual environment)
An OS agnostic alternative is to take advantage of PyCharm’s convenient Project Interpreter configuration. In PyCharm, I'll go to File -> Settings, and click on the gear icon next to the Project Interpreter field to select “Create VirtualEnv”. In the “Create Virtual Environment” window, I'll set the location to my “/vfxpiper” installation directory, appending “venv” at the end - this is where all virtualenv files (project Python interpreter and related packages) will be stored. I’ll also make sure my “Base interpreter” is set to Python 3.4, the standard for this project.



The virtual environment is now all set, PyCharm should automatically detect and activate it every time I open my piper project in the IDE. Now we can start installing all the Python packages required for developing the pipeline system. In the same “Settings” window, let’s click on the plus-shaped “Install” icon and add the following (please note the specific package versions):


A convenient alternative, which I often employ, is to use the command line to install the required packages from the /piper/requirements.txt file included in the Piper git repo.

(Example in Windows PowerShell)
PS C:\vfxpiper> .\venv\Scripts\Activate.ps1 (activating the virtual environment)
(venv) PS C:\vfxpiper> pip install -r .\piper\requirements.txt (installing the required packages defined in the piper repo)
So here is how my project structure looks like inside of PyCharm:


Up next, now that our environment is properly set up, it’s time to write some pipeline code!

Comments

Popular posts from this blog

03 - VFX Database Design

VFX Database Design TLDR : Python can be used to create and manipulate relational SQL databases to represent all kinds of data involved in VFX production - artists, departments, projects, assets, sequences, shots, tasks, resources, versions, etc. In order to organize our data and easily keep track of our assets, we will use a relational database. While some smaller studios might only use a directory structure system or a NoSQL database such as MongoDB, good old relational SQL databases are by far the most widely used and arguably most efficient way to manage data in a VFX context. I’m not claiming this is the best road to take, but if it’s good enough for most global VFX powerhouses – it’s good enough for us! Note that throughout this entire guide, I will be focusing on clarity and functionality, rather than hardcore programing efficiency and ultra-fast performance. Before writing any code, we should consider what our database should look like conceptually and what tables

02 - The VFX Pipeline in Brief

The VFX Pipeline in Brief TLDR : Projects (a.k.a shows) have sequences and assets. Sequences are made up of shots. Shots can contain assets. Assets and shots have certain tasks that result in resources, which can have many versions.

01 - Before We Begin…

Before We Begin... TLDR : Python is widely used in making movies. This guide is meant for those with at least a basic understanding of Python. You will need to download 3rd party tools to follow along with this guide.