You are not logged in.

#1 2023-09-02 21:03:15

jones
Member
Registered: 2013-03-14
Posts: 276

Noob question: setting up a virtual environment for python (packages)

Hope this is the right forum.

So. Python noob here.
Alright. It's trivial to install python. But to install packages from the python ecosystem, one should use a virtual environment or bear the responsibility of managing the magical clusterf... um, chaos of conflicting package names, (co-)dependencies if one were to install a python package in a non-virtual environment, i.e. possibly overwriting or editing a file which was created by pacman or will be in a future moment.

In the the last section on the wiki page, it says to install python-pipenv (sure, already done) and then

Basic usage

All commands can be executed in the project folder, and pipenv will recognize the specific situation - whether a virtualenv exists in the directory, locating it, and running on the specific virtual interpreter when pipenv is executed.

More information at [1], [2], [3].

The first link is: https://pipenv.pypa.io/en/latest/
On there, it says to install pipenv with:

$ pip install --user pipenv

which produces

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
    python-xyz', where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Arch-packaged Python package,
    create a virtual environment using 'python -m venv path/to/venv'.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
    If you wish to install a non-Arch packaged Python application,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. Make sure you have python-pipx
    installed via pacman.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

Ok.
I'm not trying to be obtuse, I rather want to make sure when I ask: the wiki wasn't simply updated, right? Because as it is, it links to the installation of pipenv through pip while its own 3-4 lines before that already include the correct (for the lack of a better term) way of installing pipenv.

Also, then on to installing python packages in that virtual environment, one should first activate the virtual environment via

$ pipenv shell

and then run something like

pipenv install ABCsomething

right?
(Or would someone know a link to a solid website for it, which is very much written like "this is one true way how it can be set up"? smile)

Offline

#2 2023-09-02 21:12:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: Noob question: setting up a virtual environment for python (packages)

jones wrote:
$ pip install --user pipenv

which produces [an error]

Was that command run within a previously created virtual environment directory?

EDIT: nevermind, I confirmed that this error message shows up even in a venv directory.  I have no experience with python-pipenv, but it is clearly not doing what the wiki says it's supposed to do.

Last edited by Trilby (2023-09-02 21:19:47)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2023-09-02 21:36:07

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Noob question: setting up a virtual environment for python (packages)

jones wrote:

Because as it is, it links to the installation of pipenv through pip while its own 3-4 lines before that already include the correct (for the lack of a better term) way of installing pipenv.

It links to the pipenv home page and it does so in a section titled "6.2 Basic usage". As you say, installation has been handled in 6.1, so it just tells you to look there for usage information. Many projects have a section/chapter in their documentation covering (manual) installation, but you want to install stuff through pacman unless there's a good reason not to, so you wouldn't normally go and copy-paste installation commands, except maybe into a PKGBUILD.

one should first activate the virtual environment via

$ pipenv shell

That's what realpython.com says, but the other linked docs say that you can start in an empty dir and the first time you use `pipenv install`, it will create the venv:
https://pipenv.pypa.io/en/latest/instal … ur-project

The archwiki said "pipenv will recognize the specific situation", which seems to mean it will create a venv in the current dir if one doesn't exist yet and you can do `install` with or without activating the venv first.

Last edited by Raynman (2023-09-02 21:37:21)

Offline

Board footer

Powered by FluxBB