Skip to content

1 item tagged “venv”

til A venv does not survive being copied to another machine

I was running a Python project in a Jupyter notebook, and a run died when I closed the browser by accident. After that I moved the work to a new computer. I copied the whole project folder across to the Desktop of the new machine, and the virtual environment, the venv folder, went with it.

Then I tried to rebuild the environment there. First PowerShell refused to run the venv activate script, because of the execution policy. I got activation working. The Python documentation for venv gives this command for that case:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

With the venv active, pip failed:

Fatal error in launcher

The copied venv still pointed at the folder where it was made, which was a Desktop path under OneDrive on the old computer. A venv does not survive being copied between machines, because its scripts hard-code the original path. I did not know that. The same documentation page says it in a warning: the scripts in an environment contain the absolute path to the interpreter of that environment, so environments are not portable, and if you need one in a new location you recreate it there.

So I deleted the venv. My habit from the old command prompt was this, and it does not work in PowerShell:

rmdir /s /q venv

Then I made a fresh venv, upgraded pip from 25.1.1 to 26.0.1, and installed the packages again: pandas, numpy, matplotlib, seaborn, scipy, scikit-learn, openpyxl, jupyter, xgboost, optuna, shap and tqdm. After that the notebook cells ran.

I did not try to repair the copied venv, so I cannot say if editing the paths inside it would have worked. I think it is better to rebuild it than to fight it.

The next day I moved back to the laptop, and that time I copied the new files across minus the venv. That night I also pasted a pip line into the terminal and it lost its first words, so the terminal gave “shap is not recognized”.

2026-02-21 / Craft / series From zero / , , ,