I had a python program that I could not get to work until I put it in a virtual environment.  Since I use it a lot, I put the following in a zsh script:

python3 -m venv ~/bin/pypath/venv
source ~/bin/pypath/venv/bin/activate
pinyin.py $FILE > ${FILE}.pinyin
deactivate

(FILE being $1 in the outer script.)

Until this week, it would always complain that the venv already exists, which I ignored as it was expected.  But this week, it instead says

Error: Command '['/Users/WGroleau/bin/pypath/venv/bin/python3.14', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

Now, the whole script (including the python part) still does what it is supposed to do, but this change is puzzling.  Should I do anything about it?

pyvenv returns non-zero exit status 1 (during the installation of pip stage) looks similar, but there are at least two differences (pyvenv & python vs. venv & Python3.14).  Also, the solution there seems a bit complicated.

4 Replies 4

It looks like you're working too hard.

You may find uv run convenient. It was designed for exactly this, and it is very fast.

You don't need to activate a virtual environment just to run a script out of it. You can just directly run

~/bin/pypath/venv/bin/pinyin.py "$FILE" > "$FILE.pinyin"

without activate or deactivate calls.

You also don't need to recreate the virtual environment every time you want to use it, so deleting the python3 -m venv ... line will avoid both forms of the error you're describing.

My python script is not inside the venv.  If I move it there and change the path in the zsh script, I can get rid of all the other stuff?

The reason the create is there is because Python refused to work without a venv, and once I finally got it working, I didn't bother to remove that line.  I don't mind the messages when the output is correct.

But would did that diagnostic message begin appearing and the other stop when neither script had been changed?

try the "uv run"

Install it with pip:

# With pip.
pip install uv

or curl:

curl -LsSf https://astral.sh/uv/install.sh | sh

read more here:
https://pypi.org/project/uv/

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.