switchon@lavalamp.biz
+27(0) 83 419 4851 / +27(0) 21 036 1165
Application & software development
Get A Quote

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact
    slider revolution 6
    Slider Revolution Plugin For WordPress
    Oct 22, 2021
    studies and courses to better yourself
    Studies And Online Courses To Better Yourself
    Nov 30, 2021

    Setup A New Python Project Like A Pro (Part 1: Virtual Environments)

    python packge index
    python packge index

    When doing development work using Python you will often find yourself using packages that you install using pip. Pip is similar to npm for Javascript, gem for Ruby, and NuGet for .NET, it is the standard package manager for Python. It allows the user to manage additional dependencies and libraries that aren’t part of the standard Python library. Pip has become so integral to the Python ecosystem that you no longer have to install it separately, and it is bundled with the Python installer. To see if you have pip installed on your machine you can type pip --version. If you get an error it is highly advisable that you update your Python version, as opposed to installing pip separately.

    To install packages using pip you simply type pip install [packageName] into your command line and pip will install your package for you. This package will now be available in any of your Python projects as long as you import it. Unlike npm which installs its dependencies locally pip will install its packages globally by default. When you have multiple projects that you’re working on, or collaborative projects it is better to keep the packages within their projects and not all global on your system. This is where and why we use virtual environments.

    The virtual environment is a package that is installed through pip using the command pip install virtualenv. Pip will install the virtualenv package, which you will then use to create local environments for each of your projects. The local environments mean that you limit the number of times you hear things like ‘but it worked on my machine’. Once we have virtualenv installed we must create a virtual environment for our project. We’ll setup a new project from scratch to illustrate this.

    Firstly, we’ll create a new folder on our filesystem to house the new project. Once we have our project folder, we need to create our virtual environment within the project folder. To do this we type virtualenv [environmentName]. The standard is to just call your virtual environment “venv”. Once virtualenv has setup our virtual environment we need to activate it. This will differ depending on your operating system. In Powershell you would activate the venv by typing .\[environmentName]\Scripts\activate.ps1, in cmd you would replace “.ps1” with “.bat”. In Linux you activate the environment by typing source ./venv/bin/activate. To leave your virtual environment you simply type deactivate.

    In my next blog post I’ll talk about git, security, and dotenv files. Check out https://pypi.org/ to have a look at all the packages available for installation through pip.

    Contact us


      Related posts:

      how to setup docker/nginx for your vue cli projectHow To Setup Docker/Nginx For Your Vue CLI Project onesignalHow To Setup And Use OneSignal For Web Apps how to setup git-ftp for windowsHow To Setup Git-ftp For Windows comparing woocommerce vs squrespace vs shopify vs wixComparing WooCommerce vs Squarespace vs Shopify vs Wix in 2020
      Share
      2
      Nicholas Driver
      Nicholas Driver
      Nicholas is a chemistry graduate who has worked previously as a project manager, managing director, and caregiver, but not as a chemist. After moving into software engineering in 2018 he has worked on big data, business intelligence, and various full-stack projects in a variety of different languages, platforms and frameworks.

      1 Comment

      1. Callum Fleming says:
        Nov 12, 2021 at 4:57 pm

        I am 100% sure that I am preaching to the converted, but have you tried pipenv (pip install pipenv) it’s a great way to setup and use different virtual environments. I used it once and now I am spoiled, there is also “Poetry”, however it seems less stable…

        Reply

      Leave a Reply Cancel reply

      Your email address will not be published. Required fields are marked *

      Lava Lamp Lab


      Like technology, a lava lamp constantly changes form, producing new conditions with every passing moment



      lava lamp lab facebook   lava lamp lab twitter   lava lamp lab linkedin   lava lamp lab instgram

      Services


      Application & software development

      Outsourced software development

      Project based resourcing

      Digital marketing & consulting

      Graphic design & consulting

      UI / UX design & consulting

      Contact Us


      +27(0) 83 419 4851

      +27(0) 21 036 1165


      switchon@lavalamp.biz


      Unit 1 Monaco Square,
      14 Church Street,
      Durbanville,
      Cape Town, 7550

      NBConsult Group


      nbconsult
      nbconnect msp
      nbclearning
      river broadband
      designer needed
      © 2023 Lava Lamp Lab (Pty) Ltd | All Rights Reserved | Privacy Policy
      Contact us now

        Application & software development

          Outsourced software development

            Project based resourcing

              Digital marketing & consulting

                Graphic design & consulting

                  UI/UX design & consulting

                    Lease an expert

                      Recruitment services

                        We are using cookies to give you the best experience on our website.

                        You can find out more about which cookies we are using or switch them off in settings.

                        Lava Lamp Lab
                        Powered by  GDPR Cookie Compliance
                        Privacy Overview

                        This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

                        Strictly Necessary Cookies

                        Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

                        If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

                        3rd Party Cookies

                        This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

                        Keeping this cookie enabled helps us to improve our website.

                        Please enable Strictly Necessary Cookies first so that we can save your preferences!

                        Cookie Policy

                        More information about our Cookie Policy