While inside a Python virtual environment I can execute which python
to get the path of the interpreter.
Once I get the path of the interpreter, I can find the site-packages
library following some simple steps
- Get the interpreter path using
which python
, this will lead to something like/my/interp/full/path/bin/python
cd
to one level above, so we'll be at/my/interp/full/path
cd
tolib
, now wer'e at/my/interp/full/path/lib
- Assume there is only one directory in the current directory, which will be called
python3.x
, the value ofx
depends on the version andcd
into it, now we're at/my/interp/full/path/lib/python3.8
site-packages
will be inside this directory
So what I'm trying to achieve is some kind of shell command/script that will use which python
and will output the full path to the site-packages
directory
Example of input->output:
If the output of which python
is /home/asdasd/zxczxc/qweqwe/bin/python
the output should be /home/asdasd/zxczxc/qweqwe/lib/python3.8/site-packages/
I'm looking for a bash solution, not Python code
CodePudding user response:
Is this what you are looking for ?
pypath=/home/asdasd/zxczxc/qweqwe/bin/python
ls -ld ${pypath%bin/python}lib/python*/site-packages/