Virtual Environment setup

Virtual environment (venv shortly) is a python mechanism where it is possible to create a space for your project and specific packages required by it.

Cases when Virtual Environment is useful

  • when you want to develop a project which will require specific version of libraries and you don’t want to mess with version which your python is using globally;
  • when you want to test your project with cooperation with different python versions and packages version
    • especially when from different reasons your target environment forces you to use specific python version or packages version
      • for example when you are developing module for legacy system
  • due to cleaning reasons – with venv you can just move whole folder with virtual env to the OS trash space and that’s it – to remove all dependencies you don’t have to manually uninstall each library
  • portability – you can easily

Working model with virtual environment

  1. (only once) installation of virtual environment
  2. activation
  3. usage (calling the code like normal usage)
  4. deactivation

During daily work it is enough to perform steps 2-3-4;

Actions to install virtual environment

  1. create new folder for venv
create new folder for your virtual env
create new folder for your virtual env

2. open command line or powershell (or shell on Linux / macOS) and run following commands:

  • go to folder above your virtual environment

cd <path>

  • establish new virtual environment

python -m venv .\my_venv\

After starting this command you should wait about 10 sec to execute.

When finished content of your folder will look like this:

new virtual environment after creating
new virtual environment after creating

  • perform activation of virtual environment – depending on OS it can be performed in following ways:
    • Linux
      • source my_venv/bin/activate
    • Windows
      • my_venv\Scripts\activate

Since now your command prompt will have prefix with the name of python environment. This will inform you that you are working on virtual environment.

Your command prompt will look like this:

command line (here Powershell) after activation of virtual environment
command line (here Powershell) after activation of virtual environment

3. Now you can start to work on jour project – just create own folder (for example MyNewProject) in the path of your virtual environment – like here:

creating own path inside virtual environment
creating own path inside virtual environment

Inside your project you can develop your application, install web framework use git version control system, etc.

  • You can see list of currently installed packages in your virtual environment over command:

pip list

  • If you want to install new libraries – just run:

pip install <your package name>

! be sure that your virtual environment is active – otherwise libraries will be installed globally

4. After finishing your work with virtual environment – just call following command:

deactivate

That’s it regarding working with virtual environment. enjoy!

Professional vs amateur software project

programming process
programming process

Most significant differences

Number of team member

Documentation and proper communication is crucial point.

  • Some team members can work remotely or on other part of the world!
    • clarifying even small issues can be a challenge when working hours are different.
  • It is worth in such cases to schedule regular meetings, in order to assure continuously information exchange process
    • Very important is to create a team which puts stress on transparency and sharing which activities are done by each team member.
    • Agile methodologies like SCRUM are supporting such processes very well; Inside SCRUM there are special meetings for it like daily SCRUM, Sprint review, Sprint planning.

Documentation is a key feature

Especially with long lasting project with many team members.

Some employee can be ill/change company/ etc. and this will mean that knowledge collected by them can be suddenly unavailable.

Docs will help to introduce new team members – this will require less time to put him on current track.

Usage of coding standards

Bigger projects with a lot of code (many thousands lines) are easier to read and maintain where the code was written conform with special standard.

Coding standards are expressing the way:

  • variables and functions naming;
  • a way of structuring the code (especially in C or Java);

Examples of such standards: clang-format, MISRA, PEP8 (for Python);

  • It is worth to use automated tools to check instantly the code standard inside IDE – like cppcheck, pc-lint, or pylint, flake8 (both last ones for python);

Usage of code-review processes

Automated checking tools (for coding standards ) are not assuring that the logic of implementation was done in a right way. To assure it there are processes where other team members are reviewing created code. This spreads good practices and knowledge across whole team.

Usage of version control system – for instance Git

Very important is also to create processes of working with such tool, for example “git-flow”. More info you can find here.

Build processes independent from IDE

  • To establish continuous integration processes
  • Allows that team members are using different IDEs
  • Example of such tool is CMake

Testing and debugging methods

Platform dependent parts should be splittet from remaining parts.

  • In such way most of code can run on the PC instead on target HW.
    • In this way it is possible to introduce unit-tests which can run in continuous integration process;

Continuous integration is automated building and testing process executed in a scheduled way. For example every night to obtain instant info about nr of bugs in the code.

Conclusion

As you can see there is a bit of points which are describing professional way of creating code. Of course it is not recommended to preform instant revolution inside your project. It is much better to perform evolution and make step by step improvement to achieve very efficient way of developing your application.

Feel free to share your opinion in the comment section.


Infos collected in this articles are based on my own experience and also on points posted here;

Python GUI Kivy Tutorial – part 1 – install Kivy library and demo running

Kivy Logo

In order to create python application with user interface it is needed to use right libraries (packages). 

One of them is Kivy. Huge advantage of this package is that it is cross-platform. So programs written with it can be run on different operating systems.

Continue reading “Python GUI Kivy Tutorial – part 1 – install Kivy library and demo running”