Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
-1
votes
1
answers
54
views
How to show all Python venvs on my server?
My command prints >>> import sys >>> print(sys.prefix) /home/DEVOPSM/CodeTest_Ucar/venv Is it possible to list all other virtual environments on Linux?
My command prints
>>> import sys
>>> print(sys.prefix)
/home/DEVOPSM/CodeTest_Ucar/venv
Is it possible to list all other virtual environments on Linux?
MJoao
(47 rep)
Jul 10, 2025, 08:41 AM
• Last activity: Jul 11, 2025, 02:48 PM
0
votes
0
answers
92
views
Is it safe to invoke `apt` from within a conda environment?
I have a Python script which manages upgrading the system by invoking `apt` with different arguments via the `subprocess` module. It relies on the `python_toolkit` and `docker` libraries, so these need to be installed. Up until now I've installed these two modules in the user's Python environment, t...
I have a Python script which manages upgrading the system by invoking
apt
with different arguments via the subprocess
module.
It relies on the python_toolkit
and docker
libraries, so these need to be installed.
Up until now I've installed these two modules in the user's Python environment, that is, the OS's Python interpreter with the libraries residing somewhere in ~/
.
Python 3.12 now strongly recommends to not use Python without a virtual environment if external libraries need to be used, which can be overridden by adding --break-system-packages
.
For this reason I've installed python_toolkit
and docker
inside a miniconda environment and now executed my script once. It seems to have worked, but I am unsure if this is safe to do, to invoke apt
from within a Conda environment, mostly due to the possible alteration of LD_LIBRARY_PATH
.
Should I better create a normal virtual environment, or might using --break-system-packages
be just as good? In my case, nothing else than those two libraries will ever be needed for an environment-less Python. Everything else runs in Conda environments.
Daniel F
(937 rep)
Jan 31, 2025, 02:54 PM
• Last activity: Feb 1, 2025, 02:30 AM
0
votes
1
answers
1325
views
I blew up python, pip, and dnf
I bought a book about cyber security in Python, and the author uses python version 3.9. I use Fedora Linux 37 and the default Linux is Linux 3.11. I set up a virtual environment and tried to install the authors' `requirements.txt` packages. The process choked; apparently the new version of python ca...
I bought a book about cyber security in Python, and the author uses python version 3.9. I use Fedora Linux 37 and the default Linux is Linux 3.11.
I set up a virtual environment and tried to install the authors'
requirements.txt
packages. The process choked; apparently the new version of python can't handle retrograde versions of, say, numpy (and other packages).
So I did something some may well criticize. I downloaded python 3.9 and compiled and installed it. It appeared to go OK. But then I noticed that both pip
and dnf
were broken.
pip
gave me the message:
-shellsession
$ pip install --upgrade pip
Could not find platform dependent libraries
Consider setting $PYTHONHOME to [:]
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/pip", line 10, in
from pip._internal.main import main
ModuleNotFoundError: No module named 'pip._internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/pip", line 17, in
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/pip", line 20, in
from pip import main
ImportError: cannot import name 'main' from 'pip' (unknown location)
And from dnf
:
-shellsession
# dnf install wireshark
Traceback (most recent call last):
File "/usr/bin/dnf", line 61, in
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
Now, call me naive, but I thought one of the rationales for virtual environments was to be able to use different python versions with a particular program.
As to what happened to my dnf
, I have no clue, but I don't know how to fix it.
Bryan Zimmer
(11 rep)
Feb 2, 2023, 11:12 PM
• Last activity: Jan 16, 2025, 03:13 PM
0
votes
2
answers
3800
views
Errno 13 Permission denied when pip upgrade or pip install
I have set up my virtual ennvironment and i'm trying to install the package but i keep on running into this error : ```ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/home/daeltam/.MyVenv/lib/python3.11/site-packages/propcache' Check the permissions.``` This happ...
I have set up my virtual ennvironment and i'm trying to install the package but i keep on running into this error :
: Could not install packages due to an OSError: [Errno 13] Permission denied: '/home/daeltam/.MyVenv/lib/python3.11/site-packages/propcache' Check the permissions.
This happens when i run :
- -m pip install discord
- install discord --user
- install discord
All of those tests have been made looking at forums. But the majority of them advice to create a virtualenv to fix this, which is already the case for me...
Running sudo pip install --upgrade pip
only gives me this error message i can't understand, no matter if i'm inside the venv or not :
: 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.
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
I am on debian if this is useful, i'm a newbie regarding linux and permissions are still a little bit obscure for me even after reading articles to understand.
**Edit with my progress :**
As below comments and answers seem to say, the problem might have been me setting up my venv with sudo during one of my tests.
So what i just tried is deleting the venv ( with sudo rm -rf .venv
)
and then creating one back with python3 -m venv .MyVenv
(i prefer that name)
But i got this error message once again : Error: [Errno 13] Permission denied: '/home/daeltam/Daeltam/.MyVenv/pyvenv.cfg'
I can still activate the Venv with source Path/bin/activate but i haven't made more tests.
Daeltam
(13 rep)
Jan 1, 2025, 01:47 PM
• Last activity: Jan 14, 2025, 03:25 PM
4
votes
1
answers
232
views
Missing "}" when running activate on tcsh
I am trying to set up a virtualenv on my tcsh and when I run a bash shell I am able to run this command perfectly source ./venv/bin/activate But when I run this same command from a tcsh I get this error message missing "}" . How can I fix it ?
I am trying to set up a virtualenv on my tcsh and when I run a bash shell I am able to run this command perfectly
source ./venv/bin/activate
But when I run this same command from a tcsh I get this error message
missing "}" .
How can I fix it ?
gansub
(143 rep)
Jan 13, 2025, 08:48 AM
• Last activity: Jan 13, 2025, 09:21 AM
0
votes
1
answers
35
views
Cant't create a Venv on Debian - No error message
I had my files transferred on another OS (from RetroPi to Debian) and I wanted to relaunch my Venv. I started by deleting the `.venv` folder I had (which was not that easy as some files were protected and this might have been my mistake). * Then ```pip install venv``` which worked perfectly. * And w...
I had my files transferred on another OS (from RetroPi to Debian) and I wanted to relaunch my Venv. I started by deleting the
.venv
folder I had (which was not that easy as some files were protected and this might have been my mistake).
* Then install venv
which worked perfectly.
* And when I try to run
-sh
(sudo) python3 -m venv .venv
it runs for a few seconds, doesn't give any message and doesn't create the .venv
file or nothing.
* Having sudo
or not in the command doesn't change anything.
* I tried changing permissions of the folder
-sh
chmod 777 folder_name
but same result.
The fact that I have no error message makes me unable to do precise research and I'm a newbie regarding Linux.
Daeltam
(13 rep)
Jan 1, 2025, 11:25 AM
• Last activity: Jan 7, 2025, 10:28 AM
0
votes
1
answers
69
views
I deleted my /etc/alternatives/ by accident
I'm on ubuntu 22.04. I was there removing the files related to libcudnn. However, I thought i was CDing inside, but an enter later, I realized that I was on sudo rm -rfing there. So, I ended up deleting the entire folder. Now, I'm wondering if can I still work on ubuntu like nothing happened? Or sho...
I'm on ubuntu 22.04. I was there removing the files related to libcudnn. However, I thought i was CDing inside, but an enter later, I realized that I was on sudo rm -rfing there. So, I ended up deleting the entire folder. Now, I'm wondering if can I still work on ubuntu like nothing happened? Or should i reinstall it? How important are those alternative links?
And as an alternative solution, (no puns intended) can I just ignore it if i start working in virtual envs?
fandn
(1 rep)
Nov 7, 2024, 12:45 AM
• Last activity: Nov 7, 2024, 06:17 AM
0
votes
3
answers
1404
views
Install Yum/Dnf in a Virtualenv
I've created a Virtualenv (with python3.6) and want to install yum/dnf package in that environment. Is there any way to do that? As `import dnf` or `import yum` giving me error in that environment -> `ModuleNotFoundError: No module named 'dnf'`, `ModuleNotFoundError: No module named 'yum'` respectiv...
I've created a Virtualenv (with python3.6) and want to install yum/dnf package in that environment. Is there any way to do that? As
import dnf
or import yum
giving me error in that environment -> ModuleNotFoundError: No module named 'dnf'
, ModuleNotFoundError: No module named 'yum'
respectively.
Rebecca
(23 rep)
Mar 8, 2022, 07:48 AM
• Last activity: Jun 24, 2024, 02:11 PM
0
votes
0
answers
742
views
AttributeError: 'RawConfigParser' object has no attribute 'readfp' when running python apps
I encountered the following error when trying to run tuir and also happened with youtube-dl ``` Traceback (most recent call last): File "/usr/bin/tuir", line 33, in sys.exit(load_entry_point('tuir==1.29.0', 'console_scripts', 'tuir')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fil...
I encountered the following error when trying to run tuir and also happened with youtube-dl
Traceback (most recent call last):
File "/usr/bin/tuir", line 33, in
sys.exit(load_entry_point('tuir==1.29.0', 'console_scripts', 'tuir')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/bin/tuir", line 25, in importlib_load_entry_point
return next(matches).load()
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
module = import_module(match.group('module'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "", line 995, in exec_module
File "", line 488, in _call_with_frames_removed
File "/usr/lib/python3.12/site-packages/tuir/__main__.py", line 291, in
sys.exit(main())
^^^^^^
File "/usr/lib/python3.12/site-packages/tuir/__main__.py", line 76, in main
fargs, bindings = Config.get_file(args.get('config'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/tuir/config.py", line 134, in get_file
config.readfp(fp)
^^^^^^^^^^^^^
AttributeError: 'RawConfigParser' object has no attribute 'readfp'. Did you mean: 'read'?
bazizi khaled
(3 rep)
May 13, 2024, 06:13 PM
2
votes
1
answers
479
views
Unable to uninstall virtualenv from debian 11
My debian OS has been through a few upgrades and is now on 11 (Bullseye). I initially started out with `python2` and now I no longer want it - I just want `python3`. [I installed `virtualenv` a long while back when I was still working with `python2`.][1] I have done a full `dist-upgrade`: $ sudo apt...
My debian OS has been through a few upgrades and is now on 11 (Bullseye). I initially started out with
python2
and now I no longer want it - I just want python3
. I installed virtualenv
a long while back when I was still working with python2
.
I have done a full dist-upgrade
:
$ sudo apt-get update
Hit:1 http://deb.debian.org/debian bullseye InRelease
Get:2 https://deb.nodesource.com/node_14.x bullseye InRelease [4,586 B]
Get:3 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Hit:4 http://deb.debian.org/debian bullseye-updates InRelease
Fetched 53.0 kB in 1s (49.9 kB/s)
Reading package lists... Done
$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
libts-dev
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
And when I check if virtualenv
is installed it says yes:
$ which virtualenv
/usr/local/bin/virtualenv
I try uninstalling it but pip
tells me it is not installed:
$ pip uninstall virtualenv
WARNING: Skipping virtualenv as it is not installed
$ sudo pip uninstall virtualenv
WARNING: Skipping virtualenv as it is not installed.
$ pip3 uninstall virtualenv
WARNING: Skipping virtualenv as it is not installed
$ sudo pip3 uninstall virtualenv
WARNING: Skipping virtualenv as it is not installed.
I also tried uninstalling with the package manager in case it was installed that way
$ sudo apt-get remove virtualenv --purge
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package 'virtualenv' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
But after all this I can still see that it is installed:
$ which virtualenv
/usr/local/bin/virtualenv
The reason I want to remove it is that it has an error when i try running it. And I'm thinking fully removing it and installing again will fix this:
$ virtualenv .
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in
from virtualenv import main
ModuleNotFoundError: No module named 'virtualenv'
Should I just delete /usr/local/bin/virtualenv
? That seems like a bad idea. How can I remove virtualenv
using a package manager?
## Update 1 - try installing virtualenv
using pip3
The installation is successful but virtualenv
still fails to run without errors:
$ pip3 install virtualenv
Defaulting to user installation because normal site-packages is not writeable
Collecting virtualenv
Using cached virtualenv-20.25.1-py3-none-any.whl.metadata (4.4 kB)
Requirement already satisfied: distlib=0.3.7 in ./.local/lib/python3.9/site-packages (from virtualenv) (0.3.8)
Requirement already satisfied: filelock=3.12.2 in ./.local/lib/python3.9/site-packages (from virtualenv) (3.13.3)
Requirement already satisfied: platformdirs=3.9.1 in ./.local/lib/python3.9/site-packages (from virtualenv) (4.2.0)
Using cached virtualenv-20.25.1-py3-none-any.whl (3.8 MB)
Installing collected packages: virtualenv
WARNING: The script virtualenv is installed in '/home/me/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed virtualenv-20.25.1
$ which virtualenv
/usr/local/bin/virtualenv
$ virtualenv --version
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in
from virtualenv import main
ImportError: cannot import name 'main' from 'virtualenv' (/home/me/.local/lib/python3.9/site-packages/virtualenv/__init__.py)
$ virtualenv .
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in
from virtualenv import main
ImportError: cannot import name 'main' from 'virtualenv' (/home/me/.local/lib/python3.9/site-packages/virtualenv/__init__.py)
And now virtualenv
exists in 2 places on the filesystem:
$ which virtualenv
/usr/local/bin/virtualenv
$ sudo find /usr/ -iname "virtualenv" | grep bin
/usr/local/bin/virtualenv
$ sudo find /home/me/.local/ -iname "virtualenv" | grep bin
/home/me/.local/bin/virtualenv
$ ls -l /home/me/.local/bin/virtualenv
-rwxr-xr-x 1 me me 238 Apr 7 13:06 /home/me/.local/bin/virtualenv
mulllhausen
(2751 rep)
Apr 7, 2024, 02:21 AM
• Last activity: Apr 7, 2024, 07:30 AM
2
votes
1
answers
1816
views
Python virtualenvwrapper and ZSH prompt
I am using archlinux with zsh and python simha@gauranga ~ % echo $SHELL /usr/bin/zsh simha@gauranga ~ % python3 --version Python 3.5.1 my .zshrc is export WORKON_HOME=~/.virtualenvs source /usr/bin/virtualenvwrapper.sh Once i open a new terminal I could create a new virtualenv in the following way....
I am using archlinux with zsh and python
simha@gauranga ~ % echo $SHELL
/usr/bin/zsh
simha@gauranga ~ % python3 --version
Python 3.5.1
my .zshrc is
export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh
Once i open a new terminal
I could create a new virtualenv in the following way. (simha is the home folder name and gauranga is the computer name)
simha@gauranga ~ % mkvirtualenv new2
Using base prefix '/usr'
New python executable in /home/simha/.virtualenvs/new3/bin/python3
Also creating executable in /home/simha/.virtualenvs/new3/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/preactivate
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/postactivate
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/get_env_details
Now i am entering the virtualenv
simha@gauranga ~ % workon new3
simha@gauranga ~ %
if we see above there is no change in the prompt to shown which env in am in.
I have followed the http://virtualenvwrapper.readthedocs.io/en/latest/tips.html for zsh prompt still its not working
the following are the postactivate and postdeactivate files
simha@gauranga ~ % tail -f .virtualenvs/postactivate .virtualenvs/postdeactivate
==> .virtualenvs/postactivate .virtualenvs/postdeactivate <==
RPROMPT="$_OLD_RPROMPT"
Santhosh
(409 rep)
Sep 1, 2016, 11:27 AM
• Last activity: Nov 10, 2023, 12:08 PM
0
votes
1
answers
3120
views
How to activate python venv in a non-bash shell?
I see most tutorials/online sources advice using either `source` or `.` (a bash built-in) to activate a python venv. For example, [this page][1] suggests to do the following in Linux: cd ~/ . bin/activate (whereas in Windows, it's just `cd\ ` and `activate`) But I need to activate a venv inside a do...
I see most tutorials/online sources advice using either
source
or .
(a bash built-in) to activate a python venv. For example, this page suggests to do the following in Linux:
cd ~/
. bin/activate
(whereas in Windows, it's just cd\
and
activate
)
But I need to activate a venv inside a docker/Dockerfile, and bash may not be available (e.g. with podman OCI images). As underlying distros such as Debian-based ones adopt PEP 668 , pip commands without the venv in old Dockerfiles cause an error that "This environment is externally managed" . The suggested way now seems to be use venv.
Considering the fact that source
is specific to certain shells, my questions are:
*Is it always necessary to use source
to activate
a venv in Linux?*
*If so, why and what's the proper way to activate venv in a general non-bash shell?*
*In particular, what's the proper way to use venv on pip commands in generic Dockerfiles?*
tinlyx
(1072 rep)
Jun 15, 2023, 02:05 PM
• Last activity: Jun 16, 2023, 04:41 AM
0
votes
1
answers
530
views
Where can I find the Python executable that PyCharm uses in its venv?
I'm using PyCharm 2022.3.2 (Community Edition) under Linux Mint 20.3. I created a new project and selected "New environment using Virtualenv" as an option. PyCharm shows "Python 3.10" as the interpreter for this project: [![PyCharm Python Interpreters][1]][1] Running my code in this project includin...
I'm using PyCharm 2022.3.2 (Community Edition) under Linux Mint 20.3. I created a new project and selected "New environment using Virtualenv" as an option. PyCharm shows "Python 3.10" as the interpreter for this project:
Running my code in this project including installing new packages into the venv all works fine. The interactive Python Console in PyCharm also confirms that Python 3.10 is being used with the executable in the venv:
However, now I want to execute my code from my regular terminal (without PyCharm). So I


cd
into my project directory and called the following:
$ source venv/bin/activate
(venv) $ which python
python not found
It does not find the python executable! The 3 symlinks in venv/bin
are all invalid (red in my terminal window):
(venv) $ ls -lah venv/bin/pyt*
lrwxrwxrwx 1 (redacted) (redacted) 19 Mar 15 09:56 venv/bin/python -> /usr/bin/python3.10
lrwxrwxrwx 1 (redacted) (redacted) 6 Mar 15 09:56 venv/bin/python3 -> python
lrwxrwxrwx 1 (redacted) (redacted) 6 Mar 15 09:56 venv/bin/python3.10 -> python
There is no /usr/bin/python3.10
installed on my system:
$ ls -lah /usr/bin/pyt*
lrwxrwxrwx 1 root root 9 Aug 8 2020 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3,5M Jul 1 2022 /usr/bin/python2.7
lrwxrwxrwx 1 root root 9 Aug 8 2020 /usr/bin/python3 -> python3.8
-rwxr-xr-x 1 root root 5,3M Nov 14 13:59 /usr/bin/python3.8
lrwxrwxrwx 1 root root 33 Nov 14 13:59 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config
lrwxrwxrwx 1 root root 16 Mar 13 2020 /usr/bin/python3-config -> python3.8-config
So where is the Python 3.10 executable located that PyCharm uses? And how can I used the venv outside of PyCharm?
Bianfable
(101 rep)
Mar 15, 2023, 12:30 PM
• Last activity: Mar 16, 2023, 07:20 AM
2
votes
2
answers
2467
views
Set alias to run python venv setup based on current directory name
Can't seem to figure out what the issue is. This is on a Fedora 37 with default setup (bash, gnome, etc...). What I want to achieve is to create an alias that creates a python virtual environment, where the folder name for the virtual environment is the name of the current working directory (somethi...
Can't seem to figure out what the issue is. This is on a Fedora 37 with default setup (bash, gnome, etc...).
What I want to achieve is to create an alias that creates a python virtual environment, where the folder name for the virtual environment is the name of the current working directory (something akin to
This is helpful especially when activating the venv (and later switching directories between project) you can easily identify which venv is enabled. But for some odd reason this is not working as I expected. To note that I don't have much experience in creating complex aliases but still. I have created the following vars in
python3 -m venv $cwd
).This is helpful especially when activating the venv (and later switching directories between project) you can easily identify which venv is enabled. But for some odd reason this is not working as I expected. To note that I don't have much experience in creating complex aliases but still. I have created the following vars in
.bashrc
:
- export cwd="pwd | rev | cut -d '/' -f1 | rev"
- If I run this in termnial it displays the directory name test
as I need it, but when running $cwd
in the terminal I get home//Projects/VueJS/test
- export cwd2="${PWD##*/}"
- This one just displays my username for some reason. I've searched here on stackoverflow and this was one of the suggested methods to get the current directory name
Some indication on how to get started or where to look for info are appreciated. I've tried to search on multiple sources but I can't seem to figure it. I read somewhere that double and single quotes make a difference, but I couldn't understand why and if it would affect this behaviour.
EDIT: To clarify, what I want my alias to run is i.e:
- python3 -m venv && source /bin/activate && [ ! -f ./requirements.txt ] || pip install -r requirements.txt
- This creates a virtual for python projects
- python3 -m venv && source /bin/activate && pip install nodeenv && nodeenv -p
- This creates virtual environments for projects that depend on nodejs, which in itself depend on python venv
calexandru
(210 rep)
Feb 8, 2023, 11:09 PM
• Last activity: Feb 11, 2023, 12:29 AM
-2
votes
2
answers
3127
views
Bash: pyvenv: command not found
I have Debian 8.5. with a python version 3.4.2 as default. I want to create a virtualenv using the python3 [venv][1] module. But running `pyvenv` in terminal is unable to find the pyvenv: bash: pyvenv: command not found There is a venv directory in `/usr/lib/python3.4`. Why i am unable to use it? [1...
I have Debian 8.5. with a python version 3.4.2 as default. I want to create a virtualenv using the python3 venv module. But running
pyvenv
in terminal is unable to find the pyvenv:
bash: pyvenv: command not found
There is a venv directory in /usr/lib/python3.4
. Why i am unable to use it?
user106035
Sep 19, 2016, 04:35 PM
• Last activity: Jul 7, 2022, 06:58 AM
1
votes
0
answers
149
views
Bash File Completion Creates Python Virtual Environment
Sometimes when I use tab file completion in a bash shell it pauses for one or two seconds before showing tab completion, and creates a Python virtual environment in my current directory. For example if I was running a command in a directory containing a single file named `example.pdf` and wanted tab...
Sometimes when I use tab file completion in a bash shell it pauses for one or two seconds before showing tab completion, and creates a Python virtual environment in my current directory.
For example if I was running a command in a directory containing a single file named
example.pdf
and wanted tab completion to finish the command:
$ ls
example.pdf
$ pdf2txt example
$ pdf2txt example.pdf
This file has text.
$ ls
bin example.pdf lib lib64 include pyvenv.cfg
The result is that I either have to remove all these files, or accept that my directories will be littered with mystery python virtual environments. In my home directory, the python venv resulting from bash tab completion just uses ~/bin
so I have random python scripts commingled with my bash scripts.
Unfortunately, I have been unable to reliably recreate this problem, but my sense is that it occurs when more complex files are present (pdfs, docx, etc.).
Because of the nature of the problem I have been unable to trouble shoot through web searches because all results are about implementing tab completion while writing Python scripts.
System information:
OS: Fedora 36 (though problem started around F34)
Kernel: 5.17.13-300.fc36.x86_64
A limited recursive list of python files (I'm assuming the venv files are identical each time):
$ find . -maxdepth 2
./bin
./bin/python3
./bin/python
./bin/python3.10
./bin/pip
./bin/pip3
./bin/pip3.10
./bin/Activate.ps1
./bin/activate
./bin/activate.csh
./bin/activate.fish
./include
./lib
./lib/python3.10
./pyvenv.cfg
Full file inventories:
tree
is here
ls -R
is here
Files related to bash_completion
:
/etc/profile.d/bash_completion
looks fairly normal
~/.config/bash_completion
doesn't exist
/usr/share/bash-completion/bash_completion
was rejected by pastebin but header says that latest version is on github
kuirolo
(11 rep)
Jun 27, 2022, 08:04 PM
3
votes
1
answers
954
views
Cannot source file using find, fzf, and xargs
I am trying to use fzf to select and activate different virtual environments. However, I am receiving the follow error: `xargs: source: No such file or directory` My command comprises three parts: `find | fzf | xargs` (1) find locates my virtual environments, (2) a virtual environment is selected us...
I am trying to use fzf to select and activate different virtual environments. However, I am receiving the follow error:
My command comprises three parts:
(1) find locates my virtual environments,
(2) a virtual environment is selected using fzf, and
(3) xargs is used to
Below is the full command:
I can directly source the file (i.e., command prompt shows entry into fzf_delete virtual environment):
I can select the virtual environment using fzf:
I have also isolated the issue to xargs by removing the dependency on find and fzf:
I have tried every variation of quoting, use of variables, string concatenation, command substitution, using bash -c, etc. that I can think of to no avail.
**How can I get xargs to source the selected file?**
PS - I am aware that null termination should be used with find, fzf, and xargs in case file names contain spaces, but that does not appear to be causing the immediate issue.
xargs: source: No such file or directory
My command comprises three parts:
find | fzf | xargs
(1) find locates my virtual environments,
(2) a virtual environment is selected using fzf, and
(3) xargs is used to
source
the selected file.Below is the full command:
find ~/.virtualenvs/ -maxdepth 1 -type d | fzf | xargs -I {} source {}/bin/activate
xargs: source: No such file or directory
I can directly source the file (i.e., command prompt shows entry into fzf_delete virtual environment):
brian:~$ source /home/brian/.virtualenvs/fzf_delete/bin/activate
(fzf_delete) brian:~$
I can select the virtual environment using fzf:
find ~/.virtualenvs/ -maxdepth 1 -type d | fzf
/home/brian/.virtualenvs/fzf_delete
I have also isolated the issue to xargs by removing the dependency on find and fzf:
echo "/home/brian/.virtualenvs/fzf_delete" | xargs -I {} source {}/bin/activate
xargs: source: No such file or directory
I have tried every variation of quoting, use of variables, string concatenation, command substitution, using bash -c, etc. that I can think of to no avail.
**How can I get xargs to source the selected file?**
PS - I am aware that null termination should be used with find, fzf, and xargs in case file names contain spaces, but that does not appear to be causing the immediate issue.
user2514157
(225 rep)
Jun 15, 2022, 11:12 PM
• Last activity: Jun 16, 2022, 05:40 AM
37
votes
2
answers
49833
views
How to run a command inside a virtualenv using systemd
I believe this should be simple but I can't get it to work properly. These are the commands I can run on command line: cd /home/debian/ap # Start a virtualenv source venv-ap/bin/activate # This needs to happen inside the virtualenv and takes ~20 seconds crossbar start # Outside the virtualenv, perha...
I believe this should be simple but I can't get it to work properly.
These are the commands I can run on command line:
cd /home/debian/ap
# Start a virtualenv
source venv-ap/bin/activate
# This needs to happen inside the virtualenv and takes ~20 seconds
crossbar start
# Outside the virtualenv, perhaps in a different command line window
python3 /home/debian/myscript.py
These commands have to be done in this order. Due to the virtualenv, the non-executable for crossbar, and the separate python script afterwards, I haven't been able to figure out the best way to get this to work. My current work-in-progress:
[Unit]
Description=Start CB
After=network.target
[Service]
Type=simple
User=debian
ExecStartPre=source /home/debian/ap/venv-ap/bin/activate
ExecStart=cd /home/debian/ap/ && crossbar start
Restart=always
[Install]
WantedBy=multi-user.target
sscirrus
(525 rep)
Dec 7, 2017, 11:38 PM
• Last activity: Mar 25, 2022, 08:33 AM
2
votes
0
answers
224
views
Installing packages in a virtual environment (not Python) using in-built package manager
I want to install packages in Linux via in-built package managers like `portage` for `Gentoo` or `pacman` for Arch. This is not regarding Python packages. I want to set up a virtual environment where all the dependencies and the package itself is installed only in that virtual environment and as soo...
I want to install packages in Linux via in-built package managers like
portage
for Gentoo
or pacman
for Arch. This is not regarding Python packages. I want to set up a virtual environment where all the dependencies and the package itself is installed only in that virtual environment and as soon as the virtual environment is thrown away, everything must go away. I want this because, I don't want any make
commands or any other way of install like emerge
or pacman -S
to affect the directories I work with now i.e. they must be only for a single time use. Many times, it is hard to find where the make
command extracts and installs the software and necessary files. Since it is only for a single-time use, I don't want those unnecessary dependencies to take up the space in my hard drive. By using a virtual environment, I don't care where the packages, dependencies and other files are installed as they all can be demolished by just deleting the virtual environment.
How to achieve this?
Suzuna Minami
(141 rep)
Jan 23, 2022, 06:50 AM
0
votes
0
answers
1804
views
Unable to connect to Jupyter notebook server (Error 404) from Pyenv virtual environment
_OS: 5.14.14-arch1-1 GNU/Linux x86_64_ _Pkgs: `jupyter`4.6.3, `jupyter-notebook`6.4.4, `pyenv`2.2.0 ]_ ------------------------------------------ My setup consists in launching jupyter from a `pyenv` virtual environment in directory `/path/to/my_directory` with all necessary packages and python modu...
_OS: 5.14.14-arch1-1 GNU/Linux x86_64_
_Pkgs:
> A connection to the notebook server could not be established. The > notebook will continue trying to reconnect. Check your network > connection or notebook server configuration. I document the trace when trying to launch : [I 14:54:07.039 NotebookApp] Loading IPython parallel extension [I 14:54:07.040 NotebookApp] Serving notebooks from local directory: /path/to/my_directory [I 14:54:07.040 NotebookApp] Jupyter Notebook 6.3.0 is running at: [I 14:54:07.041 NotebookApp] http://localhost:8888/ [I 14:54:07.041 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). ERROR:asyncio:Exception in callback () handle: ()> Traceback (most recent call last): File "/home/USER/.pyenv/versions/3.7.0/lib/python3.7/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) RuntimeError: Cannot enter into task wait_for= cb=[IOLoop.add_future..() at /home/USER/.pyenv/versions/3.7.0/lib/python3.7/site-packages/tornad/ioloop.py:688]> while another task cb=[IOLoop.add_future..() at /home/USER/.pyenv/versions/3.7.0/lib/python3.7/site-packages/tornado/ioloop.py:688]> is being executed. [I 14:54:09.773 NotebookApp] Kernel started: ad69df20-22a6-40b2-9778-5e1aa8781898, name: [I 14:54:12.770 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports [I 14:54:15.783 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports [I 14:54:18.785 NotebookApp] 302 GET /notebooks/01_cpu-only_inference.ipynb (127.0.0.1) 2.010000ms [I 14:54:18.795 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports [I 14:54:21.803 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports [W 14:54:24.814 NotebookApp] KernelRestarter: restart failed [W 14:54:24.815 NotebookApp] Kernel ad69df20-22a6-40b2-9778-5e1aa8781898 died, removing from map. [W 14:54:30.901 NotebookApp] Replacing stale connection: ad69df20-22a6-40b2-9778-5e1aa8781898:2eb96ae1751841d7801d200795a4bb30 [W 14:55:09.826 NotebookApp] Timeout waiting for kernel_info reply from ad69df20-22a6-40b2-9778-5e1aa8781898 [E 14:55:09.829 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: ad69df20-22a6-40b2-9778-5e1aa8781898) [W 14:55:09.832 NotebookApp] 404 GET /api/kernels/ad69df20-22a6-40b2-9778-5e1aa8781898/channels?session_id=2eb96ae1751841d7801d200795a4bb30 (127.0.0.1): Kernel does not exist: ad69df20-22a6-40b2-9778-5e1aa8781898 [W 14:55:09.848 NotebookApp] 404 GET /api/kernels/ad69df20-22a6-40b2-9778-5e1aa8781898/channels?session_id=2eb96ae1751841d7801d200795a4bb30 (127.0.0.1) 38952.030000ms referer=None ***EDIT 1***
- rolled back
_Pkgs:
jupyter
4.6.3, jupyter-notebook
6.4.4, pyenv
2.2.0 ]_
------------------------------------------
My setup consists in launching jupyter from a pyenv
virtual environment in directory /path/to/my_directory
with all necessary packages and python modules pre-installed and building a custom iPython kernel for that specific environment. Making the custom iPython kernel available in the notebook session involves:
$ cd /path/to/my_directory
$ pyenv local 3.7.0
$ python -m pip install -r
$ ipython kernel install --user --name --display-name "Python3.7.0 ()"
$ jupyter notebook
... followed by choosing "File > New Notebook" in Jupyter console menu, and picking "my_kernel" in the new notebook browser window. This method has worked flawlessly until today.
Yesterday everything worked, launching the custom kernel included. Today is a different day. Changes were basically a few package upgrades, among them a number of minor updates concerning builds:
[2021-10-27T08:42:39+0200] [ALPM] upgraded npm (8.1.0-1 -> 8.1.1-1)
[2021-10-27T21:42:20+0200] [ALPM] upgraded c-ares (1.18.0-1 -> 1.18.1-1)
[2021-10-27T21:42:20+0200] [ALPM] upgraded cmake (3.21.3-1 -> 3.21.4-1)
[2021-10-27T21:42:20+0200] [ALPM] upgraded jupyter-nbconvert (6.1.0-1 -> 6.1.0-2)
[2021-10-27T21:42:20+0200] [ALPM] upgraded jupyter (4.6.3-2 -> 4.6.3-3)
[2021-10-27T21:42:20+0200] [ALPM] upgraded ldb (2:2.4.0-1 -> 2:2.4.1-1)
[2021-10-27T21:42:20+0200] [ALPM] upgraded librsvg (2:2.52.0-1 -> 2:2.52.3-1)
[2021-10-27T21:42:20+0200] [ALPM] upgraded mercurial (5.9.2-1 -> 5.9.3-1)
[2021-10-27T21:42:21+0200] [ALPM] upgraded portmidi (217-9 -> 236-1)
[2021-10-27T21:42:21+0200] [ALPM] upgraded pyenv (2.1.0-1 -> 2.2.0-1)
[2021-10-27T21:42:21+0200] [ALPM] upgraded python-pygame (2.0.1-2 -> 2.0.1-3)
[2021-10-27T21:42:21+0200] [ALPM] upgraded python-sqlalchemy (1.3.23-1 -> 1.4.25-1)
[2021-10-27T21:42:21+0200] [ALPM] upgraded smbclient (4.15.0-1 -> 4.15.1-1)
[2021-10-27T21:42:21+0200] [ALPM] upgraded samba (4.15.0-1 -> 4.15.1-1)
[2021-10-28T08:18:33+0200] [ALPM] upgraded systemd-libs (249.5-2 -> 249.5-3)
[2021-10-28T08:18:33+0200] [ALPM] upgraded device-mapper (2.03.13-1 -> 2.03.14-1)
[2021-10-28T08:18:33+0200] [ALPM] upgraded cryptsetup (2.4.1-1 -> 2.4.1-3)
[2021-10-28T08:18:33+0200] [ALPM] upgraded lvm2 (2.03.13-1 -> 2.03.14-1)
[2021-10-28T08:18:33+0200] [ALPM] upgraded openexr (3.1.2-1 -> 3.1.3-1)
[2021-10-28T08:18:33+0200] [ALPM] upgraded python-joblib (1.0.1-1 -> 1.1.0-1)
[2021-10-28T08:18:33+0200] [ALPM] upgraded python-ptyprocess (0.7.0-1 -> 0.7.0-2)
[2021-10-28T08:18:33+0200] [ALPM] upgraded python-pexpect (4.8.0-3 -> 4.8.0-4)
[2021-10-28T08:18:33+0200] [ALPM] upgraded systemd (249.5-2 -> 249.5-3)
[2021-10-28T08:18:34+0200] [ALPM] upgraded systemd-sysvcompat (249.5-2 -> 249.5-3)
The error I get when trying to launch is:
> Connection failed> A connection to the notebook server could not be established. The > notebook will continue trying to reconnect. Check your network > connection or notebook server configuration. I document the trace when trying to launch : [I 14:54:07.039 NotebookApp] Loading IPython parallel extension [I 14:54:07.040 NotebookApp] Serving notebooks from local directory: /path/to/my_directory [I 14:54:07.040 NotebookApp] Jupyter Notebook 6.3.0 is running at: [I 14:54:07.041 NotebookApp] http://localhost:8888/ [I 14:54:07.041 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). ERROR:asyncio:Exception in callback () handle: ()> Traceback (most recent call last): File "/home/USER/.pyenv/versions/3.7.0/lib/python3.7/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) RuntimeError: Cannot enter into task wait_for= cb=[IOLoop.add_future..() at /home/USER/.pyenv/versions/3.7.0/lib/python3.7/site-packages/tornad/ioloop.py:688]> while another task cb=[IOLoop.add_future..() at /home/USER/.pyenv/versions/3.7.0/lib/python3.7/site-packages/tornado/ioloop.py:688]> is being executed. [I 14:54:09.773 NotebookApp] Kernel started: ad69df20-22a6-40b2-9778-5e1aa8781898, name: [I 14:54:12.770 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports [I 14:54:15.783 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports [I 14:54:18.785 NotebookApp] 302 GET /notebooks/01_cpu-only_inference.ipynb (127.0.0.1) 2.010000ms [I 14:54:18.795 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports [I 14:54:21.803 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports [W 14:54:24.814 NotebookApp] KernelRestarter: restart failed [W 14:54:24.815 NotebookApp] Kernel ad69df20-22a6-40b2-9778-5e1aa8781898 died, removing from map. [W 14:54:30.901 NotebookApp] Replacing stale connection: ad69df20-22a6-40b2-9778-5e1aa8781898:2eb96ae1751841d7801d200795a4bb30 [W 14:55:09.826 NotebookApp] Timeout waiting for kernel_info reply from ad69df20-22a6-40b2-9778-5e1aa8781898 [E 14:55:09.829 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: ad69df20-22a6-40b2-9778-5e1aa8781898) [W 14:55:09.832 NotebookApp] 404 GET /api/kernels/ad69df20-22a6-40b2-9778-5e1aa8781898/channels?session_id=2eb96ae1751841d7801d200795a4bb30 (127.0.0.1): Kernel does not exist: ad69df20-22a6-40b2-9778-5e1aa8781898 [W 14:55:09.848 NotebookApp] 404 GET /api/kernels/ad69df20-22a6-40b2-9778-5e1aa8781898/channels?session_id=2eb96ae1751841d7801d200795a4bb30 (127.0.0.1) 38952.030000ms referer=None ***EDIT 1***
- rolled back
pyenv
, jupyter
and jupyter-nbconvert
, one by one and in that order. For example:$ sudo pacman -U jupyter-nbconvert-6.1.0-1-any.pkg.tar.zst
- rebooted each time -> no change
- reinstalled Python virtual environment binaries for 3.7.0$ pyenv uninstall 3.7.0
$ pyenv install 3.7.0
- reinstalled Python 3.7.0 shims$ pyenv rehash
- set out to reinstall my 3GB of required packages in 3.7.0 virt- env, starting with ipykernel
. Result is Segmentation fault (core dumped)
.
$ cd /path/to/my_directory
$ pyenv local 3.7.0
$ python -m pip install ipykernel
Segmentation fault (core dumped)
$ python -m pip install -U pip
Segmentation fault (core dumped)
$ ... etc...
Still troubleshooting this. Any suggestion welcome.
Cbhihe
(2880 rep)
Oct 28, 2021, 01:44 PM
• Last activity: Dec 14, 2021, 08:08 PM
Showing page 1 of 20 total questions