0

I needed to rename a python venv virtual environment in macOS 12.1

I followed the instructions in https://stackoverflow.com/a/68400551

I have already done

mv old_venv new_venv

Then

cd /path/to/new_venv/bin

Then

sed -i 's/old_venv/new_venv/g' *

I get the following error sed: 1: "Activate.ps1": invalid command code A

I tried this

sed -i'.original' 's/old_venv/greendeploy-py3101/g' * after reading https://stackoverflow.com/a/4247319/80353

Then I get sed: python: in-place editing only works for regular files

What is another way to rename venv in macOS 12.1?

I know i can delete and then do a new venv from scratch but i would like to rename where possible.

Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
  • 1
    sed -i'.original' should work for plain files, but it sounds like you have a directory named "python", and it's (reasonably) refusing to edit that. – Gordon Davisson Jan 30 '22 at 08:17

1 Answers1

0

Ok I solved it

I just realized from the 2nd link i provided in the question there's an alternative to using perl

From https://stackoverflow.com/a/4247319/80353, last line

perl -i -pe's/old_venv/new_venv/g' *

So the whole solution is

At the folder level

mv old_venv new_venv (no change)

Then

cd /path/to/new_venv/bin (no change)

Then

perl -i -pe's/old_venv/new_venv/g' * (use this instead of sed)

Kim Stacks
  • 10,202
  • 35
  • 151
  • 282