Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Solved] : pipx library installation and adding path

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
larry77
Posts: 585
Joined: 2006-09-24 17:59
Has thanked: 6 times
Been thanked: 1 time

[Solved] : pipx library installation and adding path

#1 Post by larry77 »

I run Debian stable on my box and I want to install the binance connector library

https://github.com/binance/binance-connector-python

to query binance.

I use pipx and everything seems to be OK (see below)

Code: Select all

$ sudo pipx install binance-connector --include-deps
⚠️  Note: normalizer was already on your PATH at /usr/bin/normalizer
  installed package binance-connector 3.5.1, installed using Python 3.11.2
  These apps are now globally available
    - normalizer
    - wsdump
⚠️  Note: '/root/.local/bin' is not on your PATH environment variable. These
    apps will not be globally accessible until your PATH is updated. Run `pipx
    ensurepath` to automatically add it, or manually modify your PATH in your
    shell's config file (i.e. ~/.bashrc).
done! ✨ 🌟 ✨
Then I do the following

Code: Select all

$ pipx ensurepath
/home/lorenzo/.local/bin is already in PATH.

⚠️  All pipx binary directories have been added to PATH. If you are sure you
want to proceed, try again with the '--force' flag.

$ sudo pipx ensurepath
[sudo] password for lorenzo: 
/root/.local/bin has been been added to PATH, but you need to open a new
    terminal or re-login for this PATH change to take effect.

You will need to open a new terminal or re-login for the PATH changes to take
effect.

Otherwise pipx is ready to go! ✨ 🌟 ✨
and everything looks fine, but then when I open a new shell and/or relogin, I still get this

Code: Select all

$ python3.11
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from binance.spot import Spot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'binance'
why is the binance library not found? Any suggestion is really appreciated and merry Xmas to everyone!
Last edited by larry77 on 2024-03-27 17:16, edited 1 time in total.

Jeremy Davis
Posts: 20
Joined: 2024-01-02 02:49
Has thanked: 3 times

Re: [Python] : pipx library installation and adding path

#2 Post by Jeremy Davis »

AFAIK pipx only puts the executables in your PATH. It doesn't put python modules in your PYTHONPATH. If you want that, you'll need to also add the relevant modules to your system PYTHONPATH. But then you'd just be ignoring the point of why pipx exists and you may as well just install the module using pip install --break-system-packages as you'll get the same end result: a mix of apt managed packages and pip managed packages which often leads to things breaking in weird and unexpected ways.

For scripting purposes, just use a venv. It's not that hard and will save you a ton of potential issues down the track. I.e. try something like this:

Code: Select all

user@ninjux projects/debian-playing$ python3 -m venv my-project
user@ninjux projects/debian-playing$ ./my-project/bin/pip install binance-connector
Collecting binance-connector
  Downloading binance_connector-3.5.1-py3-none-any.whl (71 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 71.9/71.9 kB 1.1 MB/s eta 0:00:00
Collecting requests>=2.31.0
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 kB 4.2 MB/s eta 0:00:00
Collecting websocket-client>=1.6.3
  Downloading websocket_client-1.7.0-py3-none-any.whl (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.5/58.5 kB 6.2 MB/s eta 0:00:00
Collecting pycryptodome>=3.15.0
  Downloading pycryptodome-3.19.1-cp35-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 2.9 MB/s eta 0:00:00
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 140.3/140.3 kB 2.8 MB/s eta 0:00:00
Collecting idna<4,>=2.5
  Downloading idna-3.6-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.6/61.6 kB 5.1 MB/s eta 0:00:00
Collecting urllib3<3,>=1.21.1
  Downloading urllib3-2.1.0-py3-none-any.whl (104 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 104.6/104.6 kB 4.1 MB/s eta 0:00:00
Collecting certifi>=2017.4.17
  Downloading certifi-2023.11.17-py3-none-any.whl (162 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 162.5/162.5 kB 3.0 MB/s eta 0:00:00
Installing collected packages: websocket-client, urllib3, pycryptodome, idna, charset-normalizer, certifi, requests, binance-connector
Successfully installed binance-connector-3.5.1 certifi-2023.11.17 charset-normalizer-3.3.2 idna-3.6 pycryptodome-3.19.1 requests-2.31.0 urllib3-2.1.0 websocket-client-1.7.0
user@ninjux projects/debian-playing$ ./my-project/bin/python --version
Python 3.11.2
user@ninjux projects/debian-playing$ ./my-project/bin/python
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from binance.spot import Spot
>>> 
So long as you use that venv python path in the shebang of any scripts you write, then they should "just work". Although be sure to use the absolute path, I was only demonstrating the theory with a relative path. Note that then running your script on a different machine might be a bit of a PITA. So if you intend to do anything more than write a few dirty scripts to run locally, I'd suggest a "proper" python project dependency manager, such as poetry.

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1412
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 46 times
Been thanked: 70 times

Re: [Python] : pipx library installation and adding path

#3 Post by None1975 »

Running pipx as sudo (or root) is VERY BAD idea...
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

Post Reply