Archive

Posts Tagged ‘virtual environment’

update all packages with pip in your virtual environment

January 5, 2017 Leave a comment

Problem
You want to update all installed packages in your virtual environment.

Solution

$ pip install pip-review
$ pip-review --local --interactive

Tip from here.

Categories: python Tags: ,

getting started with Kivy

January 24, 2016 Leave a comment

Intro
Kivy is an open source library for developing multi-touch applications. It is cross-platform (Linux/OSX/Windows/Android/iOS) and released under the terms of the MIT License.

It comes with native support for many multi-touch input devices, a growing library of multi-touch aware widgets and hardware accelerated OpenGL drawing. Kivy is designed to let you focus on building custom and highly interactive applications as quickly and easily as possible.” (source)

Problem
How to install it in a virtual environment? I could install it but when I wanted to create a basic app, it dropped some error messages (“pygame or sdl missing”).

Solution
Instead of Pygame I chose the SDL way. So under Manjaro I had to install globally the following packages:

sudo pacman -S gstreamer sdl2_ttf sdl2_mixer sdl2_image

Maybe gstreamer is not necessary, I’m not sure.

I suggest working with Kivy in a Python 2 virtual environment. Why? If you want to build your app for Android, then you can use the buildozer tool. However, at the moment it doesn’t support Python 3 :( I’m sure it’ll change but at the moment stick with Python 2.

Then, in your virtual environment, install these:

pip install cython
pip install kivy

Let’s try if it works. Activate your virt. env. and launch the Python interpreter in it. Then try this code:

>>> from kivy.app import App
>>> App().run()

If you get a blank window with black background, then everything is fine.

Links

Pew: A tool to manage multiple virtual environments written in pure Python

January 4, 2016 Leave a comment

Problem
You are fed up with virtualenv and virtualenvwrapper.

Solution
Use Pew, which is a new kid on the block. I collected my notes about it here, where I also provide two convenience scripts. I don’t want to copy all that here, so check out the GitHub link.

pyvenv: create virtual environmets for Python 3.4+

January 1, 2015 Leave a comment

For creating virtual environmets, I’ve used virtualenvwrapper so far. However, Python 3.4 contains the command pyvenv that does the same thing. Since it also installs pip in the virt. env., it can replace virtualenvwrapper.

I like to store my virtual environments in a dedicated folder, separated from the project directory. virtualenvwrapper, by default, stores the virt. env.’s in the ~/.virtualenvs folder. Since I got used to this folder, I will continue to keep my virt. env.’s in this folder.

pyvenv
Say we have our project folder here: ~/python/webapps/flasky_project. Create a virt. env. for this the following way:

pyvenv ~/.virtualenvs/flasky_project

It will create a Python 3 virt. env.

virtualenv / virtualenvwrapper
For the sake of completeness, I also write here how to create virt. env.’s with virtualenv and virtualenvwrapper:

# blog post: http://goo.gl/oEdtT3

# virtualenvwrapper for Python 3 or Python 2
mkvirtualenv -p `which python3` myenv3
mkvirtualenv -p `which python2` myenv2

# virtualenv for Python 3 or Python 2
virtualenv -p python3 myproject3
virtualenv -p python2 myproject2

# When the env. is created, activate it
# and launch the command python within.
# Verify if it's the correct version.

TL; DR
If you use Python 3.4+ and you need a virt. env., use the command “pyvenv“.