简体   繁体   中英

Why does my virtualenv python3 work fine on my local machine but not when I upload the virtualenv to the server?

If I install a virtualenv on my local machine, activate it and try to run python3 then it works fine (with the imported modules). However, after I send it to the live server (using scp and filezilla) it gives the error:

-bash: /<path>/venv4/bin/python3: cannot execute binary file: Exec format error

This also happens with python and python3.8 in the same package.

I have tried reinstalling virtualenv and pipx, recreating the virtualenv and reuploading a few times.

It seems that it can't find the module, as when I activate the virtualenv on the live server and type "which python3" then it shows me the system python3:

/usr/bin/python3

It also does not work if I try to execute the venv's python3 directly, using the full path.

The reason I'm doing this is because the old virtualenv I was using has stopped working because it can't seem to find the installed modules anymore. I'm not sure why.

Any help would be much appreciated.

I believe some pip packages contain more than just python code, and must be compiled. If your host OS is different from your server OS, or you have different libraries installed, the host-compiled code will not be compatible with your server.

Common practice is to create a file with a list of required packages, using something like

pip freeze > requirements.txt

and rebuild the environment on the server, using something like

pip install -r requirements.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM