Code Monkey home page Code Monkey logo

nuke_pyenv_tutorial's Introduction

Using pyenv to install python libraries for Nuke

pyenv

Pyenv allows multiple versions of python to be installed on your machine and easily switch between those versions.

Before continuing the tutorial, you'll need to install pyenv and pyenv-virtualenv.

Find out how to to install pyenv for your operating system here:
https://github.com/pyenv/pyenv

Installing pyenv-virtualenv will allow us to isolate our installation in it's own environment:
https://github.com/pyenv/pyenv-virtualenv

Now that pyenv and pyenv-virtualenv are installed, let's take a look at Nuke.

What version of python does Nuke use?

In order to make sure we don't have version conflicts with our installed python libraries, we need to make sure we're using the same version of python as Nuke.

What version does Nuke use? Let's find out!

In Nuke, open your script editor and let's use the platform library to find out more about Nuke's python version.

import platform
print platform.python_version()

You can find out even more detailed information by using sys

import sys
print sys.version

I'm using Nuke 12.1v3 for this tutorial so the result for either option is 2.7.16.

Now that we know the version that Nuke uses, let's install it using pyenv

Install Nuke's version of python

Use pyenv's install command to install 2.7.16

pyenv install 2.7.16

Make a virtual instance for our nuke installs

pyenv virtualenv 2.7.16 nuke12

Let's run the same commands we ran in Nuke to find out more about our python install. Let's activate our new instance on 2.7.16.

pyenv shell nuke12
python -c "import platform; print platform.python_version()"
python -c "import sys; print sys.version"

Install some python libraries

pip install pyyaml
pip install pymongo

We need to find the path to where the nuke12 virtualenv places it's site-packages. We'll use this to link it in our init.py file

python -c 'import site; print(site.getsitepackages())'
# '/Users/homedir/.pyenv/versions/nuke12/lib/python2.7/site-packages'

Using sys, we can append the path that python uses to source imports.
Put this in your init.py file

import sys
sys.path.append("/Users/homedir/.pyenv/versions/nuke12/lib/python2.7/site-packages")

Open up Nuke and in the script editor, try an import of one of the two libraries we installed.

try:
    import yaml
except Exception as e:
    print str(e)

try:
    import pymongo
except Exception as e:
    print str(e)

If you don't get any errors, that's it.
Happy Comping!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.