Python

Learn how to work with Python in Codesphere. Learn how to change Python versions or browser our tutorials.

December 14, 2023 2 Min Read
Python
Python

Simon Pfeiffer

Head of Product @ Codesphere

Python is a popular, high-level programming language that is widely used in a variety of fields. It is known for its simplicity, readability, and flexibility, as well as its large standard library and active developer community.

Using Python in Codesphere

Python 3.8 comes pre-installed in all workspaces. The easiest way to get started with Python in Codesphere is to create a workspace from the Hello, Python! template. This template contains a ready to run Flask app. Once provisioned head over to CI-Pipeline, run the prepare stage and, once completed, the run stage.

Changing the Python version in Codesphere

Pyenv is pre-installed in all workspaces and can be used to install other versions of Python. If you want to persistently change the version, i.e. across workspace restarts or for off-when-unused workspaces, you need to follow the steps described below.

These are the steps:

  1. Set PYENV_ROOT to /home/user/app/.pyenv via setup/env vars
  2. Open a new terminal (existing terminals don't get updated env vars)
  3. Type pipenv install --python 3.9.0 (or any other Python version)
  4. Or alternatively add PIPENV_YES=1 pipenv install --python 3.9.0 to your CI prepare stage
  5. Activate with pipenv shell

Important note for Micro and Free workspaces: following the previous steps may lead to the terminal/pipeline being killed halfway through - this is because the installation of CPython versions tends to exceed the compute and storage in these workspaces. Current alternatives are using a pypy version of your target Python version (list available versions via: pyenv install --list | grep -i pypy - use non-src versions) or if that is incompatible with some of your packages upgrade to a bigger workspace plan.

To work with a pypy Python version follow these steps:

  • Install with pyenv install pypy3.9-7.3.8 - replace last part with your target version
  • Create a pipenv with pipenv --python /home/user/app/.pyenv/versions/pypy3.9-7.3.8/bin/python3.9 - replace last part with your target version
  • Activate with pipenv shell

Explore our Python Tutorials

Customer Use Cases

How Project Count uses Codesphere to make their deployment and hosting trivial
> “With AWS, even just getting something set up that works is a huge pain and then platforms like Heroku are so inflexible with what you can and can’t install for your project. It just made sense to use Codesphere” This past week we sat down with Simon Pfeiffer, Founder and CEO of Project Count. Project Count aims to make product carbon footprints easily accessible for everyone, so they can better understand how to reduce their footprint. Before founding Project Count, Simon earned a Masters d

About the Author

Python

Simon Pfeiffer

Head of Product @ Codesphere

Simon’s responsibilities cover our product marketing efforts & the roadmap. He is a former green tech founder & IT consultant at KPMG. He shares trends & insights from building Codesphere.

More Posts

Monitoring & Alerting

Monitoring & Alerting

Learn how to access Codesphere's built in resource monitoring and check the uptime of your applications.

Path based routing

Path based routing

Learn how to connect multiple independent applications to a single domain by associating different paths with distinct workspaces

Staging Environments

Staging Environments

Learn how to use Codesphere's Domains to improve your release process.