Vagrant VM and venv

Hi All!

I have an issue I was hoping someone could help me with :sweat_smile:

I’m trying to follow an online tutorial I found and have hit a bit of a roadblock with the setting up of the project

My goal is to create and set up a virtual machine with a python virtual environment where I can work on the project

I have installed both, but the issue I’m facing is my python virtual environment venv doesn’t seem to be connected to the files on my VSCODE, like I have installed a module called spacy in my venv, but it is not being picked up by VSCODE as an installed module

I get the feeling that somehow VSCODE is still pointing towards the main python modules and not the modules installed on my venv

Is there anyway to check this and change it so I can properly work in my venv?

In VS Code there’s available in Command Palette a Python: Select interpreter option.

2 Likes

Thanks for the suggestion!

But how would you point to a virtual machines directory?

your suggestion pointed me to some documentation on virtual environments that reminded me that as long as I execute the file in the connected vagrant terminal, vscodes warnings about the module not existing (because it is pointing to the default interpretor) aren’t relevant, as it runs fine without errors.

it will be SUPER annoying having to keep looking at the squiggly yellow line of imperfection, but I think I can hold on :cry:

Thanks again!

I’m not entirely sure, as I haven’t used it, but there’s extension for VS Code that might give better integration by using ssh to connect to VM: Remote - SSH - Visual Studio Marketplace

1 Like

This depends a lot on the initial setup of the VM. I’m going to assume the VM is running locally or reachable on your local network, in which case often times you can use your OS file explorer to mount the virtual disk and then browse it like you would any other drive…other times it’s not so easy. Once it’s mounted, you can point VS Code at it. If you use the Command Palette in Code to select a Python Interpreter there is an option to “+ Enter interpreter path…” where you could probably point it at the python executable pertaining to your VM’s particular venv (contained somewhere in the virtual disk you’ll need to mount).

Working with an IDE outside of a VM where you’re building code can be kind of tricky in a dev situation. If you’ll be routinely doing that sort of thing I would look into container systems like Docker instead of a full VM – they excel at exactly this scenario. Or, if it’s a graphical VM environment, maybe just install your IDE in the VM and code form there? If you’re following an online tutorial, the whole point of using the VM to begin with is probably to have a unified experience across various student’s systems and not deal with this sort of problem to begin with. Just my two cents.

1 Like

This is super helpful! I hadn’t even considered mounting my vm’s so I can access them; another tool added to my toolbelt :smiley:

I am still getting my head around using vm’s and such so this has lifted a little bit of the fog over my eyes. I will look into using docker for future projects as I am planning to do a few until I get comfortable with the process.

I appreciate the 2 cents!

Cheers

Don

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.