Eu gostaria de usar python no Ubuntu, mas preciso usar pacotes adicionais que não são instalados por padrão. Existe uma maneira de fazer isso? Até agora parece muito frustrante, já que não devo instalar pacotes adicionais pelo pip3 'global', mas, por outro lado, as versões 'venv' não estão funcionando.
Preciso de um pacote 'keyring' e 'pycryptodome'. Tenho uma instalação nova do Ubuntu 24.04. Quando tento:
$ pip3 install pycryptodome
Recebo este erro:
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.12/README.venv for more information.
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.
user:~$
Então, acho que não devo instalar pacotes 'system-wide'. Então, criei um .venv e instalei o pacote pycryptodome. Mas então não posso usar o pacote 'keyring' naquele .venv:
user:~$ python3 -m venv .venv
user:~$ source .venv/bin/activate
(.venv) catchman:~$ pip3 install keyring
Collecting keyring
Using cached keyring-25.6.0-py3-none-any.whl.metadata (20 kB)
Collecting SecretStorage>=3.2 (from keyring)
Using cached SecretStorage-3.3.3-py3-none-any.whl.metadata (4.0 kB)
Collecting jeepney>=0.4.2 (from keyring)
Using cached jeepney-0.8.0-py3-none-any.whl.metadata (1.3 kB)
Collecting jaraco.classes (from keyring)
Using cached jaraco.classes-3.4.0-py3-none-any.whl.metadata (2.6 kB)
Collecting jaraco.functools (from keyring)
Using cached jaraco.functools-4.1.0-py3-none-any.whl.metadata (2.9 kB)
Collecting jaraco.context (from keyring)
Using cached jaraco.context-6.0.1-py3-none-any.whl.metadata (4.1 kB)
Collecting cryptography>=2.0 (from SecretStorage>=3.2->keyring)
Using cached cryptography-44.0.0-cp39-abi3-manylinux_2_28_x86_64.whl.metadata (5.7 kB)
Collecting more-itertools (from jaraco.classes->keyring)
Using cached more_itertools-10.6.0-py3-none-any.whl.metadata (37 kB)
Collecting cffi>=1.12 (from cryptography>=2.0->SecretStorage>=3.2->keyring)
Using cached cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.5 kB)
Collecting pycparser (from cffi>=1.12->cryptography>=2.0->SecretStorage>=3.2->keyring)
Using cached pycparser-2.22-py3-none-any.whl.metadata (943 bytes)
Using cached keyring-25.6.0-py3-none-any.whl (39 kB)
Using cached jeepney-0.8.0-py3-none-any.whl (48 kB)
Using cached SecretStorage-3.3.3-py3-none-any.whl (15 kB)
Using cached jaraco.classes-3.4.0-py3-none-any.whl (6.8 kB)
Using cached jaraco.context-6.0.1-py3-none-any.whl (6.8 kB)
Using cached jaraco.functools-4.1.0-py3-none-any.whl (10 kB)
Using cached cryptography-44.0.0-cp39-abi3-manylinux_2_28_x86_64.whl (4.2 MB)
Using cached more_itertools-10.6.0-py3-none-any.whl (63 kB)
Using cached cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (479 kB)
Using cached pycparser-2.22-py3-none-any.whl (117 kB)
Installing collected packages: pycparser, more-itertools, jeepney, jaraco.context, jaraco.functools, jaraco.classes, cffi, cryptography, SecretStorage, keyring
Successfully installed SecretStorage-3.3.3 cffi-1.17.1 cryptography-44.0.0 jaraco.classes-3.4.0 jaraco.context-6.0.1 jaraco.functools-4.1.0 jeepney-0.8.0 keyring-25.6.0 more-itertools-10.6.0 pycparser-2.22
(.venv) user:~$ python3
Python 3.12.3 (main, Jan 17 2025, 18:03:48) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyring
>>> keyring.get_keyring().get_password('Chrome Keys', 'Chrome Safe Storage') == None
True
Por outro lado, o 'sistema' python pode fazer isso:
user:~$ python3
Python 3.12.3 (main, Jan 17 2025, 18:03:48) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyring
>>> len(keyring.get_keyring().get_password('Chrome Keys', 'Chrome Safe Storage'))
24
Então parece que preciso usar .venv, mas naquele ambiente virtual o pacote (keyring) não está funcionando e eu deveria usar os pacotes python do sistema. Mas quando eu os uso, não consigo instalar nenhum outro pacote. Tipo um Catch-22
O Ubuntu suporta algum desenvolvimento python utilizável? Ou como eu deveria fazer isso funcionar?
Aqui estão as informações do meu sistema (avise-me se precisar de mais):
user:~$ cat /etc/issue
Ubuntu 24.04.1 LTS \n \l
user:~$ uname -a
Linux ryzen 6.8.0-51-generic #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
user:~$ plasmashell --version
plasmashell 5.27.11
user:~$ kf5-config --version
Qt: 5.15.13
KDE Frameworks: 5.115.0
kf5-config: 1.0
user:~$ python3 --version
Python 3.12.3
user:~$ pip3 --version
pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.12)