Discussion:
Installing a python package with pipx
(too old to reply)
Richmond
2024-06-01 16:20:01 UTC
Permalink
I have been trying to install this:

https://pypi.org/project/musicpy/#description

with not much success.

I have done these:

sudo aptitude install pip
sudo aptitude install pipx
pipx ensurepath
pipx install --include-deps musicpy

(logged out and in to get updated PATH)

pipx run musicpy
'musicpy' executable script not found in package 'musicpy'.
Available executable scripts:

I think it is installed, but how do I run it?
Richard
2024-06-01 16:30:01 UTC
Permalink
If you haven't closed the terminal window/logged out, you need to run
source .bashrc. Running pipx ensurepath should have said something like
that.

Richard
Post by Richmond
https://pypi.org/project/musicpy/#description
with not much success.
sudo aptitude install pip
sudo aptitude install pipx
pipx ensurepath
pipx install --include-deps musicpy
(logged out and in to get updated PATH)
pipx run musicpy
'musicpy' executable script not found in package 'musicpy'.
I think it is installed, but how do I run it?
Richmond
2024-06-01 16:50:01 UTC
Permalink
Post by Richard
If you haven't closed the terminal window/logged out, you need to run
source .bashrc. Running pipx ensurepath should have said something
like that.
(logged out and in to get updated PATH)
Richard
2024-06-01 16:50:01 UTC
Permalink
Looking at the package, no wonder it fails. musicpy doesn't contain
anything that can be executed. So pipx run can't work for obvious reasons.
You'll have to install it with pipx install and use it in a python script.

https://pypi.org/project/musicpy/

Richard
Post by Richard
If you haven't closed the terminal window/logged out, you need to run
source .bashrc. Running pipx ensurepath should have said something
like that.
(logged out and in to get updated PATH)
Richmond
2024-06-01 17:20:01 UTC
Permalink
Post by Richard
Looking at the package, no wonder it fails. musicpy doesn't contain
anything that can be executed. So pipx run can't work for obvious
reasons. You'll have to install it with pipx install and use it in a
python script.
https://pypi.org/project/musicpy/
OK so I have found:

./.local/pipx/venvs/musicpy/lib/python3.11/site-packages/musicpy/musicpy.py

But:

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.
Post by Richard
import musicpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'musicpy'

I guess I have to tell python where to look?
Richard
2024-06-01 17:50:01 UTC
Permalink
That's the point of venv's. pipx runpip should do the trick. Or the classic
way: source path/to/venv/bin/activate. That way you activate the position
virtual environment (venv) created in that directory with all packages
installed in that venv.

Richard
Post by Richmond
I guess I have to tell python where to look?
Richmond
2024-06-01 20:10:01 UTC
Permalink
Post by Richard
That's the point of venv's. pipx runpip should do the trick. Or the
classic way: source path/to/venv/bin/activate. That way you activate
the position virtual environment (venv) created in that directory
with all packages installed in that venv.
I got it working by doing:

python3 -m venv .local/pipx/venvs/musicpy/

.local/pipx/venvs/musicpy/bin/python3.11

Then I was able to import musicpy from the python shell.

How bewildering!

Thanks.
Richard
2024-06-01 20:40:01 UTC
Permalink
Pretty much just what pipx does.
Post by Richmond
python3 -m venv .local/pipx/venvs/musicpy/
.local/pipx/venvs/musicpy/bin/python3.11
Then I was able to import musicpy from the python shell.
How bewildering!
Thanks.
Richmond
2024-06-01 21:10:01 UTC
Permalink
Post by Richard
Pretty much just what pipx does.
Well I don't know how.

Now I need to run idle in my new environment. I have installed it

.local/pipx/shared/bin/pip install idle

and it is here:

.local/pipx/shared/lib/python3.11/site-packages/idle.py

but I don't know how to run it. I just get errors.
Richard
2024-06-01 21:30:01 UTC
Permalink
A packages documentation is always your best friend:
https://pypi.org/project/idle/

Also, python script isn't a necessarily a standalone executable. And also,
you shouldn't just wildly mix pipx commands with pip commands if you don't
know what you are doing. Either create a venv with python3 -m venv or use
pipx, not both. Once created, stick to these separate paths. And read the
documentation of pipx while you're at it. Sure, venvs are easy to handle,
as you can just delete them and start from scratch, but mixing commands
without knowing what one is doing is just a recipe for desaster.
Post by Richmond
Post by Richard
Pretty much just what pipx does.
Well I don't know how.
Now I need to run idle in my new environment. I have installed it
.local/pipx/shared/bin/pip install idle
.local/pipx/shared/lib/python3.11/site-packages/idle.py
but I don't know how to run it. I just get errors.
Richmond
2024-06-01 22:00:01 UTC
Permalink
A packages documentation is always your best friend: https://pypi.org
/project/idle/
Yes it makes it look easy there, but:

import idle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".local/pipx/shared/lib/python3.11/site-packages/idle.py", line 4, in <module>
from layout import *
ModuleNotFoundError: No module named 'layout'
Also, python script isn't a necessarily a standalone executable. And
also, you shouldn't just wildly mix pipx commands with pip commands
if you don't know what you are doing. Either create a venv with
python3 -m venv or use pipx, not both. Once created, stick to these
separate paths. And read the documentation of pipx while you're at
it. Sure, venvs are easy to handle, as you can just delete them and
start from scratch, but mixing commands without knowing what one is
doing is just a recipe for desaster.
I don't know what I am doing for sure. But I did not wildly mix, I just
kept trying things until I found something which worked. Most things
didn't, and still don't.
Richard
2024-06-01 22:10:01 UTC
Permalink
Post by Richmond
A packages documentation is always your best friend: https://pypi.org
/project/idle/
import idle
File "<stdin>", line 1, in <module>
File ".local/pipx/shared/lib/python3.11/site-packages/idle.py", line 4, in <module>
from layout import *
ModuleNotFoundError: No module named 'layout'
That's what I'm talking about. You wildly mix commands together that don't
go together. And whatever is off with your paths. Things of pipx installed
packages should be in .local/bin and .local/shared/pipx. At least on Debian
that's the default. No idea what you did.
Post by Richmond
Also, python script isn't a necessarily a standalone executable. And
also, you shouldn't just wildly mix pipx commands with pip commands
if you don't know what you are doing. Either create a venv with
python3 -m venv or use pipx, not both. Once created, stick to these
separate paths. And read the documentation of pipx while you're at
it. Sure, venvs are easy to handle, as you can just delete them and
start from scratch, but mixing commands without knowing what one is
doing is just a recipe for desaster.
I don't know what I am doing for sure. But I did not wildly mix, I just
kept trying things until I found something which worked. Most things
didn't, and still don't.
You are, your last comment is more than proof enough.

You should just remove everything you installed with pipx, create a
separate venv - without using pipx! - and solely work inside it. And don't
touch pipx for anything that's not meant as a standalone CLI program, like
yt-dlp, speedtest and the sorts. Maybe that way you can't do that much
wrong.

At this point this is hardly a Debian related topic. You should first learn
more about Python venvs and their package managers.
Richmond
2024-06-02 11:50:02 UTC
Permalink
Post by Richard
A packages documentation is always your best
friend: https://pypi.org
Post by Richard
/project/idle/
import idle
  File "<stdin>", line 1, in <module>
  File ".local/pipx/shared/lib/python3.11/site-packages/idle.py",
line 4, in <module>
    from layout import *
ModuleNotFoundError: No module named 'layout'
That's what I'm talking about. You wildly mix commands together that
don't go together. And whatever is off with your paths. Things of pipx
installed packages should be in .local/bin and .local/shared/pipx. At
least on Debian that's the default. No idea what you did.
I don't think your assessment is correct, as I have booted opensuse,
where I do not even have pipx installed and have not used it. I did
these commands:

1059  pip install musicpy
 1062  pip install idle

I got the layout error so:

 1065  pip install layout

cured the layout error but then I got a gui error

 1067  pip install gui

There is no such package.

.local/lib/python3.6/site-packages/idle.py", line 26, in <module>
    gui.mainloop()
NameError: name 'gui' is not defined
Richmond
2024-06-02 12:00:01 UTC
Permalink
OK Back on Debian, I removed the one package installed with pipx, which
was musicpy, then tried to install it with pip, but got this message
which actually tells me to use pipx. (There is no package python-musicpy).

pip install musicpy
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.11/README.venv for more information.
Richard
2024-06-02 12:10:01 UTC
Permalink
python3 -m venv venv
source venv/bin/activate
pip install musicpy

That's how its done. Also, complaining here about something that doesn't
even work on other distros and thus can't be a Debian problem doesn't make
that much sense.
Post by Richmond
OK Back on Debian, I removed the one package installed with pipx, which
was musicpy, then tried to install it with pip, but got this message
which actually tells me to use pipx. (There is no package python-musicpy).
pip install musicpy
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.11/README.venv for more information.
Richmond
2024-06-02 12:30:01 UTC
Permalink
Post by Richard
That's how its done. Also, complaining here about something that
doesn't even work on other distros and thus can't be a Debian
problem doesn't make that much sense.
I am not complaining, I am trying to find out how to get it working. And
as pip (and pipx) are debian packages I think it is reasonable to
discuss it on the debian user list.
Richard
2024-06-02 13:00:01 UTC
Permalink
If it where an issue with pip or pipx, yes. But as you pointed out
yourself, it's also happening on OpenSuse, so the issue can't be pip or
pipx, but rather either what you are trying to install or your
understanding of it.
Post by Richmond
I am not complaining, I am trying to find out how to get it working. And
as pip (and pipx) are debian packages I think it is reasonable to
discuss it on the debian user list.
Richmond
2024-06-02 12:50:01 UTC
Permalink
Post by Richard
python3 -m venv venv
source venv/bin/activate
pip install musicpy
OK thanks. And apparently to get idle working I do:

python -m idlelib.idle
Loading...