0

I have the following setup: I am on a M1 Mac host machine and am using Ubuntu on a virtual machine created by multipass. The code I work on requires Ubuntu for various reasons I prefer coding on the Mac.

I have created a shared folder which contains the source code of the package and a virtual environment (python3 -m venv environment) in which I installed the package. I am working on the code using VS Code which allows me to select an interpreter. However, this virtual environment only contains an alias to the binary in the /usr/ folder in the virtual machine (which is not shared with the host).

Is it possible to have the binary in the folder created by venv? Or is there another way for VS Code to access the binary as the interpreter?

I tried selecting the alias as the interpreter in VS Code but, as expected, this did not work. I also found this article in which the author claims that python3 -m virtualenv creates its own binary, which I could not confirm (readlink environment/bin/python outputs /usr/bin/python3).

rioV8
  • 24,506
  • 3
  • 32
  • 49
  • Hi plasma-dom, so your question is how to replace python3 binary in your `venv` from Ubuntu Machine so it can run on M1 mac? – Bijay Regmi May 03 '23 at 07:20
  • You can run `python3 -m venv myenvironment` on mac and activate the environment with `source myenvironment/bin/activate` and then install your package with `pip3 install mypackage` – Bijay Regmi May 03 '23 at 07:21
  • Have you tried set `"python.defaultInterpreterPath"` in `settings.json` manually? – MingJie-MSFT May 03 '23 at 07:49
  • @BijayRegmi kind of, my problem is that the python3 binary is not a binary but a symlink, and it points to the `/usr/bin/` folder in the VM that my Mac has no access to. To your second comment: I cannot do `pip3 install mypackage` since it requires some other packages which are not supported on M1 mac. – plasma-dom May 03 '23 at 07:53
  • @MingJie-MSFT I am not sure what you want me to set it to. As I mentioned, the host (Mac) has no access to the `/usr/bin/` folder of the VM. AFAIK it is not possible to also mirror this folder to the host. That's why I wanted to create a separate python3 binary which I can install in the shared folder. – plasma-dom May 03 '23 at 08:00
  • I am not very familiar with Mac, does [this answer](https://stackoverflow.com/a/33272796/18359438) solve your problem? – MingJie-MSFT May 03 '23 at 08:53
  • you are still not able to import the standard modules, `os`, `sys`, they are in the installed Python directory, that is part of the PYTHONPATH when you activate the virt env. Install Python also on the virtual folder and adjust the activate script to set the correct PYTHONPATH – rioV8 May 03 '23 at 09:32
  • @MingJie-MSFT Unfortunately no, but thanks for the help :) – plasma-dom May 03 '23 at 14:27
  • @rioV8 what exactly do you mean by "install python on the virtual folder"? – plasma-dom May 03 '23 at 14:28
  • Oops, **shared folder**, but Ubuntu Python does not run on M1 – rioV8 May 03 '23 at 15:58
  • I mean, that would be the question: How do I install python in a custom location. I searched all day about this, but it seems like it is not really wanted to do that. I tried installing it from source using `dpgk` but there were some errors. – plasma-dom May 04 '23 at 08:46

0 Answers0