element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
  • About Us
  • 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 287 subscribers
  • Views 7478 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
  • shabaz
    0 shabaz over 1 year ago in reply to JWx

    Your example uses root, that's not advised (apart from for installing virtualenv itself, unless that is already installed).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • JWx
    0 JWx over 1 year ago in reply to shabaz

    yes - old, bad habit... but - at the other hand - if user installs something using pip, it is installed on local account (not system-wide), so somewhat like a common  venv...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • JWx
    0 JWx over 1 year ago in reply to JWx

    btw - original problem is only visible when installing from root account:

    user is not getting any warning:

    service@e14-panda:~$ pip install numpy
    Defaulting to user installation because normal site-packages is not writeable
    Collecting numpy
      Downloading numpy-1.26.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 3.8 MB/s eta 0:00:00
    Installing collected packages: numpy
      WARNING: The script f2py is installed in '/home/service/.local/bin' which is not on PATH.
      Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
    Successfully installed numpy-1.26.1

    only root gets - so examples are based on question's context:

    root@e14-panda:/home/service# pip install numpy
    Collecting numpy
      Using cached numpy-1.26.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
    Installing collected packages: numpy
    Successfully installed numpy-1.26.1
    WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: pip.pypa.io/.../venv

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • BigG
    0 BigG over 1 year ago

    Yes, I find this new requirement rather painful. If it's my device and the library download is just for that device then I just use the option "--break-system-packages".

    Otherwise, I think Python Poetry is worth considering instead of using venv.

    https://python-poetry.org/

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

    Hah, fortunately, I had not noticed and followed along as a standard user anyway.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • 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