0

I've just setup a new environment for my project and uploaded a python repository including bin, lib and project folder. I'm pretty sure I did same previously and it worked without problem. Now when doing the same on an AWS environment I get the error -bash: /projects/scrapy/bin/python2.7: cannot execute binary file. However when doing source /projects/scrapy/bin/activate it successfully activates the environment.

From what I understand, python should be able to execute without any issue no matter the environment ?

Any help or pointing to the right direction would be much appreciated!

5
  • Locally I use a Mac. Everything always worked perfectly until uploading the folder to the AWS virtual machine. isn't python working on a standalone environment ? Commented Jul 25, 2018 at 16:15
  • python should be able to execute without any issue no matter the environment ? No, the Python binary is tied to your specific OS and computer architecture. Commented Jul 25, 2018 at 16:15
  • A Python binary compiled to run on Macos will not work on Linux. Create a new virtualenv with a Python binary compiled for Linux, and install the same packages there. Use pipenv or a requirements.txt file to transfer the dependencies from Mac to Linux. Commented Jul 25, 2018 at 16:16
  • @MartijnPieters so actually the successful activation doesn't mean that it is working, right ? Commented Jul 25, 2018 at 16:18
  • 1
    nope, all it means is that you copied the activate shell script to another environment that also has a working shell interpreter that supports setting the PATH environment variable. Commented Jul 25, 2018 at 16:22

1 Answer 1

2

python should be able to execute without any issue no matter the environment ?

No, the Python binary is tied to your specific OS and computer architecture. Python source code can usually be run on different machines (provided you didn't use OS-specific features), but that's only made possible by compiling a Python interpreter for the specific target environment first.

In other words, a Python binary compiled to run on macOS will not work on Linux.

All that source bin/activate achieves is that it configures your terminal setting to use the bin directory as the first directory on the PATH search path. This doesn't make bin/python work in another environment, it just means that both environments have a working shell interpreter that can run that script.

Create a new virtualenv with a Python binary compiled for Linux, and install the same packages there. Use Pipenv or a requirements.txt file to transfer the dependencies from Mac to Linux.

For example, using Pipenv you'd copy over the Pipfile and Pipfile.lock files to the other computer, then run pipenv install in the directory there and re-create the virtualenv and dependencies from those files.

I recommend you read up on Python development best practices in the The Hitchhiker’s Guide to Python; this includes such topics on how to manage an environment for a project.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, 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.