0

I'm trying to create venv using "python3 -m venv venv" remotely. However, it fails:

> ssh sv3-01 "python3 -m venv venv"
Error: Command '['/home/ubuntu/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

FYI:

  • ssh config has sv3-01 configuration set correctly and working
  • ssh sv3-01 "ls -lah" works fine returning usual ls file list from the sv3-01 remote server
  • Executing "python3 -m venv venv" directly on the sv3-01 server works absolutely fine. Python3-dev and python3-venv are installed successfully on the server already.

What do I do wrong?

uzla
  • 515
  • 1
  • 4
  • 20
  • I have seen this mention as working due to a bug, or you could set the explicit path. python3 -m venv .env – Madison Courto Apr 24 '23 at 22:40
  • does it work if you use a different name than venv? – BrendanOtherwhyz Apr 24 '23 at 22:40
  • Run `which pyhton3` directly and through ssh to see if any difference. – Philippe Apr 24 '23 at 22:50
  • Does that command depend on any environment variables being set correctly? How are those variables set? – Kenster Apr 25 '23 at 01:24
  • Thanks to all for the comments and questions. Quick answers: no Environment vars involved; different name to venv has no impact on issue; explicit path did not help. HOWEVER, this morning I found solution. See it in the Answer section on this page. – uzla Apr 25 '23 at 09:53

1 Answers1

0

The solution I have found is to add "--without-pip" like this

ssh sv3-01 "python3 -m venv --without-pip venv"

The reason is that python3 -m venv also does automatic pip installation, which fails when done remotely. I don't know the root cause for that, but the root cause does not matter in this case.

Excluding automatic pip installation within python3 -m venv does the job (obviously without pip in it). To mitigate pip absence, I added additional command to the remote ssh call:

ssh sv3-01 "sudo apt-get -y install pip"

It could be merged in one liner:

ssh sv3-01 "cd /desired_path && python3 -m venv --without-pip venv && sudo apt-get -y -qq install pip" 

Voila!

uzla
  • 515
  • 1
  • 4
  • 20
  • Automatic pip installation fails when the system has prohibited it. It doesn't matter whether it's remote or local. Debian and derived distros like Ubuntu do this because they want to break up the Python package into `python3` and `python3-pip`; you need to install the latter if you want to use `pip`. – tripleee Apr 25 '23 at 09:59