Skip to content

How to Install Python Packages into CoCalc

Harald Schilly edited this page Aug 23, 2018 · 12 revisions

About Python Packages in CoCalc

You may need to install a Python package in a CoCalc project.

CoCalc already includes hundreds of packages for several Python development environments.

If a package may have general use but is not already installed in CoCalc, you can open a support request to install it. Uncomplicated install requests are typically handled within 1 business day for paying customers. Install will happen faster if you include as much as possible of the following information:

  • Python 2 or Python 3 language version
  • link to package website
  • special requirements and dependencies to build & install
  • include a complete example that we can easily use to verify that we properly installed the software.

You can install additional packages yourself, but only at user-permission level. CoCalc accounts do not have superuser (root) privileges. Software must be installed into user-writeable parts of the filesystem.

In a nutshell: a CoCalc project is a Linux user account under the username "user". Therefore, installing software and libraries can be done in ~/.local (i.e. /home/user/.local), which is the canonical location for user installs. Furthermore, in case the documentation mentions to specify a custom "prefix" path, set this to ~/.local.

How to install Python packages as a CoCalc user

Regarding Python 2 vs. Python 3:

  • Python 2: use pip2 or python2 -- pip and python should default to these variants.
  • Python 3: use pip3 or python3 below.

Note: pip and python commands below should be entered in a CoCalc .term file.

pip

If your package can be installed with pip, then use pip install --user [package-name].

Your project must have the "Internet access" upgrade in order to download software from the pip repository to your project. The Python pip command will not work unless you upgrade your project to have internet access.

setup.py

If your package is in a folder inside your project (e.g., you uploaded it) with a setup.py folder, you can do either python setup.py install --user or pip install --user --upgrade ./

(Some setup instructions alternatively mention python setup.py install --home)

If pip requires that any external dependencies be downloaded, then your project must have internet access.

virtualenv

You can avoid the need for --user flags if you work inside a Python virtual environment. See Virtualenv for more information.

Sage

A special case is SageMath, which is a fully integrated environment built on top of Python. To install a Python package in Sage, it needs to also install into your local home directory. To accomplish that, first start the Sage-environment in a Terminal, and then issue the pip-install command with --user. For example:

  1. sage -sh for the sage environemnt
  2. pip install --user git+https://github.com/videlec/sage-flatsurf

If it happens that Sage doesn't recognize packages in your local path, prepend them to your path via running

import site, sys
sys.path.insert(0, site.USER_SITE)
Clone this wiki locally