element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum I don't understand python venv
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 16 replies
  • Answers 4 answers
  • Subscribers 285 subscribers
  • Views 7036 views
  • Users 0 members are here
  • raspberry pi 5
  • the environment is externally managed
  • raspberry pi 5 bookworm
  • python packages
  • pip install
  • venv
  • python3
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

I don't understand python venv

cstanton
cstanton over 1 year ago

This is going to be a growing pain for a lot of people that pick up the Raspberry Pi 5 with Bookworm, too.

A lot of guides and instructions say to do:

pip install <package>

Or

apt-get install python3-<package>

The 'problem' from a usability perspective now, is that when you try to do:

pip install <package>

It complains at you with "this environment is externally managed" and to use a venv, and I don't understand them. It doesn't direct you on how to use a venv either.

I understand why we're doing it this way, so that we do not have a clash between operating system repository packages and the python pip installed packages.

Can someone explain to me how to use pip with a venv with an example package? I'm trying to find guides online and of course everyone has an opinion on how to do it three different ways but they also don't explain what exactly venv is doing or how to use it after installing the package with pip.

  • Sign in to reply
  • Cancel

Top Replies

  • JWx
    JWx over 1 year ago +5 suggested
    Python suffers from multitude of interpreter and library versions - which can lead to the situation that one library cannot co-exist with another, because they - for example - are dependent on another…
  • shabaz
    shabaz over 1 year ago +4 suggested
    I watched a training video on it a while back. It suggested the following: (1) First off, check you've got 'virtualenv' installed. That's easy to do by typing which virtualenv (2) If you don't have…
  • michaelkellett
    michaelkellett over 1 year ago in reply to cstanton +3 suggested
    There's a comprehensive, but not perfect, description here. https://realpython.com/python-virtual-environments-a-primer/ which may help. MK
Parents
  • shabaz
    0 shabaz over 1 year ago

    I watched a training video on it a while back. It suggested the following:

    (1) First off, check you've got 'virtualenv' installed. That's easy to do by typing which virtualenv

    (2) If you don't have it installed then install it : ) You can use root (e.g. sudo) and type apt-get install python3-virtualenv to install the default one for your Linux build.

    (3) Now, it's a good idea to create a folder for housing your virtual environments. Personally, I create a folder off my home folder, called development, and then in there you could create a folder called (say) virt_python or whatever

    (4) In that virt_python folder, whenever you're ready for a new virtual environment, simply type virtualenv bob (or whatever name you wish to call it). What's going on in the background, is that the virt_python/bob folder gets created, and inside that are folders for Python executable and libraries, and all these are completely independent from your normal /bin/python or wherever you normally have python and any libraries installed.

    (5) Whenever you wish to use your new environment! Type: source ~/development/virt_python/bob/bin/activate 

    (6) Now you can use Python as normal (i.e. create a folder anywhere and write your app just as you normally would), but it will be in your virtual environment. You'll know that, because your command prompt will state (bob). Whenever you use pip install, it will be into your virtual environment.

    (7) When you're done, just type deactivate and you'll be out of the wonderland.

    With PyCharm (here's a Windows screenshot) it tends to create a separate virtual environment for every project (you can see it creates a subfolder called venv) but it's not necessary. If you wished, you could share a virtual environment with multiple projects, although it's just disk space, so not really necessary, since storage is cheap, and at least guarantees no clashes of libraries. 

    image

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • shabaz
    0 shabaz over 1 year ago

    I watched a training video on it a while back. It suggested the following:

    (1) First off, check you've got 'virtualenv' installed. That's easy to do by typing which virtualenv

    (2) If you don't have it installed then install it : ) You can use root (e.g. sudo) and type apt-get install python3-virtualenv to install the default one for your Linux build.

    (3) Now, it's a good idea to create a folder for housing your virtual environments. Personally, I create a folder off my home folder, called development, and then in there you could create a folder called (say) virt_python or whatever

    (4) In that virt_python folder, whenever you're ready for a new virtual environment, simply type virtualenv bob (or whatever name you wish to call it). What's going on in the background, is that the virt_python/bob folder gets created, and inside that are folders for Python executable and libraries, and all these are completely independent from your normal /bin/python or wherever you normally have python and any libraries installed.

    (5) Whenever you wish to use your new environment! Type: source ~/development/virt_python/bob/bin/activate 

    (6) Now you can use Python as normal (i.e. create a folder anywhere and write your app just as you normally would), but it will be in your virtual environment. You'll know that, because your command prompt will state (bob). Whenever you use pip install, it will be into your virtual environment.

    (7) When you're done, just type deactivate and you'll be out of the wonderland.

    With PyCharm (here's a Windows screenshot) it tends to create a separate virtual environment for every project (you can see it creates a subfolder called venv) but it's not necessary. If you wished, you could share a virtual environment with multiple projects, although it's just disk space, so not really necessary, since storage is cheap, and at least guarantees no clashes of libraries. 

    image

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
  • cstanton
    0 cstanton over 1 year ago in reply to shabaz

    Thanks for this step-by-step!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube