0

[UPDATE] This seems to be a problem with the Parallels VM (https://forum.parallels.com/threads/execution-files-located-on-shared-folders-mount-with-exec.352815/). Thanks to all who commented!

I have a strange problem with my virtualenv (on Ubuntu 20.04). I activate my virtualenv as follows.

aravind@vetinari:test_venv$ rm -r venv
aravind@vetinari:test_venv$ python -m venv venv
aravind@vetinari:test_venv$ source venv/bin/activate

I then install an empty package with one script called test_version.py which is also successful.

(venv) aravind@vetinari:test_venv$ python -m pip install -e .
Obtaining file:///media/psf/Home/projects/test_venv
Installing collected packages: test-venv
  Attempting uninstall: test-venv
    Found existing installation: test-venv 0.0.1.dev0
    Not uninstalling test-venv at /media/psf/Home/projects/test_venv, outside environment /media/psf/Home/projects/test_venv/venv
    Can't uninstall 'test-venv'. No files were found to uninstall.
  Running setup.py develop for test-venv
Successfully installed test-venv

When I run it with the virtualenv python, it runs fine.

(venv) aravind@vetinari:test_venv$ /media/psf/Home/projects/test_venv/venv/bin/python /media/psf/Home/projects/test_venv/venv/bin/test_version.py 
3.8.10

However, when I run it as a standalone script, I get this error.

(venv) aravind@vetinari:test_venv$ /media/psf/Home/projects/test_venv/venv/bin/test_version.py 
bash: /media/psf/Home/projects/test_venv/venv/bin/test_version.py: /media/psf/Home/projects/test_venv/venv/bin/python: bad interpreter: Invalid argument

Here are the contents of the installed script.

(venv) aravind@vetinari:test_venv$ cat /media/psf/Home/projects/test_venv/venv/bin/test_version.py 
#!/media/psf/Home/projects/test_venv/venv/bin/python
# EASY-INSTALL-DEV-SCRIPT: 'test-venv==0.0.1.dev0','test_version.py'
__requires__ = 'test-venv==0.0.1.dev0'
__import__('pkg_resources').require('test-venv==0.0.1.dev0')
__file__ = '/media/psf/Home/projects/test_venv/bin/test_version.py'
with open(__file__) as f:
    exec(compile(f.read(), __file__, 'exec'))

Note that the shebang interpreter (media/psf/Home/projects/test_venv/venv/bin/python) in the script is present and it works fine when I execute it with that python but not when I run it as a standalone script.

Here are the contents of the script.

(venv) aravind@vetinari:test_venv$ cat bin/test_version.py
#!/usr/bin/env python
import platform; print(platform.python_version())

and the setup.py.

(venv) aravind@vetinari:test_venv$ cat setup.py
#!/usr/bin/env python

from setuptools import setup, find_packages

setup(name='test_venv',
      version='0.0.1dev',
      description='Test',
      author='Aravind Sundaresan',
      maintainer='Aravind Sundaresan',
      packages=find_packages(),
      scripts=["bin/test_version.py",],
      install_requires=[],
      zip_safe=False
      )
11
  • Please provide setup.py and other relevant files to reproduce the problem. Commented Sep 27, 2021 at 20:04
  • #!/media/psf/Home/projects/test_venv/venv/bin/python Does that program exist? Commented Sep 27, 2021 at 20:07
  • @PeterBadida I have updated the question with the information you requested. Is there an easy way to provide the package? Commented Sep 27, 2021 at 20:27
  • 1
    If not, my next step would be to pull out strace and watch for the actual syscall that fails. Commented Sep 27, 2021 at 20:30
  • 1
    @AravindSundaresan I added the parallels tag for you. Re the running, you're facing a rather nasty issue. Consider creating a new question just for Parallels I guess or simply switch to a different emulator for the quickest fix. Maybe there's even a simple converter somewhere online and if not, check the history command for your VM, copy-paste files to host and reinstall in a different emulator. Commented Sep 28, 2021 at 21:14

1 Answer 1

1

Ah, after the comment I see you're sharing a folder. Virtual environment is OS-specific, therefore it's a different executable (similar like here).

MacOS venv works only on MacOS. Linux venv works only on Linux. Create venv from scratch in that VM.

file <path to python> should show the executables differ, thus bash can't execute it because it can't be executed on Linux (not an ELF binary).

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

2 Comments

Thanks for the answer, Peter. I want to clarify that while the folder is shared from the host (Mac) the virtualenv was created on Linux as you suggested. I was not trying to share a virtualenv across OSes. This error happens when the virtualenv is on a shared folder so it definitely seems to be related to that. However, I'm still trying to figure out what the issue is.
@AravindSundaresan never heard of Parallels, but I'm glad you found the problem. Perhaps try to utilize a different emulator such as VirtualBox or VMWare player or even switch to Docker for a lightweight usage of the platform (works on MacOS and Windows too).

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.