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 7041 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
  • JWx
    0 JWx over 1 year ago

    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 library, but in different versions.

    To overcome this - as I understand - virtual environments were created, to have local execution sandbox with all the required libraries

    To create one:

    #python3 -m venv /root/test-venv

    optionally - install required package first:

    #apt install python3.10-venv

    To activate it:

    #source /root/test-venv/bin/activate

    and then pip is local copy and packages should be installed inside this venv (to not interfere with other versions)

    (test-venv) root@e14-panda:~# which pip
    /root/test-venv/bin/pip
    /root/test-venv/bin/pip
    (test-venv) root@e14-panda:~# pip list
    Package    Version
    ---------- -------
    pip        22.0.2
    setuptools 59.6.0

    Install something

    (test-venv) root@e14-panda:~# pip install pandas
    Collecting pandas
      Downloading pandas-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.3 MB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.3/12.3 MB 5.1 MB/s eta 0:00:00
    Collecting tzdata>=2022.1
      Downloading tzdata-2023.3-py2.py3-none-any.whl (341 kB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 341.8/341.8 KB 3.3 MB/s eta 0:00:00
    Collecting python-dateutil>=2.8.2
      Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 KB 3.8 MB/s eta 0:00:00
    Collecting numpy>=1.22.4
      Downloading numpy-1.26.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 5.1 MB/s eta 0:00:00
    Collecting pytz>=2020.1
      Downloading pytz-2023.3.post1-py2.py3-none-any.whl (502 kB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 502.5/502.5 KB 5.2 MB/s eta 0:00:00
    Collecting six>=1.5
      Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
    Installing collected packages: pytz, tzdata, six, numpy, python-dateutil, pandas
    Successfully installed numpy-1.26.1 pandas-2.1.1 python-dateutil-2.8.2 pytz-2023.3.post1 six-1.16.0 tzdata-2023.3

    List again:

    (test-venv) root@e14-panda:~# pip list
    Package         Version
    --------------- ------------
    numpy           1.26.1
    pandas          2.1.1
    pip             22.0.2
    python-dateutil 2.8.2
    pytz            2023.3.post1
    setuptools      59.6.0
    six             1.16.0
    tzdata          2023.3

    Deactivate venv:

    (test-venv) root@e14-panda:~# deactivate

    Try pip again:

    root@e14-panda:~# pip list
    Command 'pip' not found, but can be installed with:
    apt install python3-pip

    There is even no pip command installed outside of venv

    • Cancel
    • Vote Up +5 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • 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
Reply
  • 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
Children
  • 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
  • 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
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