You are not logged in.

#1 2023-11-16 06:32:55

genji
Member
Registered: 2023-08-13
Posts: 61

Python: ModuleNotFoundError: No module named 'pick'

Hello there, trying to run a script from PIA to export their WireGuard config files, and I can't run it because it says

[snow@arch ~/pia-wg]$ python generate-config.py 
Traceback (most recent call last):
  File "/home/snow/pia-wg/generate-config.py", line 2, in <module>
    from pick import pick
ModuleNotFoundError: No module named 'pick'

So I tried (this one is REALLY annoying, by the way, why doesn't pip work on this OS?)

[snow@arch ~/pia-wg]$ pip install pick
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.

and it did not work, so then I tried

[snow@arch ~/pia-wg]$ sudo pacman -S python-pick
error: target not found: python-pick
[snow@arch ~/pia-wg]$ sudo pacman -S pick
error: target not found: pick
[snow@arch ~/pia-wg]$ sudo pacman -S pip-pick
error: target not found: pip-pick

And now I am stuck

Thanks for any help!

Offline

#2 2023-11-16 07:14:16

agent1983
Member
Registered: 2023-11-16
Posts: 1

Re: Python: ModuleNotFoundError: No module named 'pick'

The error message is telling you what to do. The package won't allow you to install it for everyone.

$ python3 -m venv venv
$ source venv/bin/activate
$ pip install pick

Offline

#3 2023-11-16 09:13:14

Malcolmlisk
Member
Registered: 2021-11-25
Posts: 10

Re: Python: ModuleNotFoundError: No module named 'pick'

This doesn't seem a problem with Arch, but let's try it.

To begin with, you need to understand what's going on when you call $ python ./module.py. What you are doing here is calling the global installation of python and then, the module.py. So everything inside this module.py will run over the global python with all the global packages. This is, usually, a bad practice, and that's why it's telling you to install it through pacman. It's suggested by the python community to use virtual environments, which is what @agent1983 did here.

Virtual environments it's like creating an encapsulated system, away from the system files, where you can install new modules and mess with it as much as you want. You can create v-envs with a lot of tools, one of the easiest and native to every python installation is venv. You can create a virtual environment by just typing $ python3 -m venv venv. This will create a virtual environment  in the folder you are right now. Whatever you install inside this environment will not be installed in the global, so every time you want to use those libraries in that project, you need to activate the venv for it. It's highly recommended to create a venv for every project.

So yes, create a new virtual environment (you can give it te name you want, it's the second argument). Activate it by sourcing the activate script. When you are inside, the console will tell you the name of your environment inside parenthesis. Then install pick and run your script.

$ python3 -m venv venv-name
$ source venv-name/bin/activate
$ pip install pick
$ python generate-config.py 

Offline

Board footer

Powered by FluxBB