Activate venv in vs code - python-3.x

I have been trying to activate a virtual environment using Python built-in module venv from VSCode, But it didn't work properly And I didn't receive any error message. However, and also If I use venv\Scripts\activate.bat command in terminal it doesn't work.

Are you correctly setting up the venv?
python3 -m venv env
Then in the below section of your vscode taskbar you will find
Then select your interpreter(env) to use:

There are three things that I would check:
Does your vs-code have a default virtual environment defined as a user setting? Is that the one your current workspace is using?
Have you moved the folder you are working in since creating a virtual environment? If so, you should edit your venv/bin/activate script so that it has the correct value for the VIRTUAL_ENV variable.
In your project, do you have a .vscode/settings.json file that is referring to the wrong location or a location which doesn't exist? Specifically thinking of the "python.defaultInterpreterPath" setting.
These are things that I came across today when I had a similar problem. Hopefully that helps someone else!

{Ctrl+shift+'}
this will open a new terminal and automatically activate your virtual environment, found this in vs code documentation for flask virtual environments.
I also tried venv\Scripts\activate.bat and it wasn't having it; however cant remember the issue I was having.
Hope this saves some one a lot of time.

Related

ghci only loads with admin

I've been trying to install Haskell platform with chocolatey but have been unable to get it working without running the command prompt as an administrator.
When I do so normally it just states that "ghci is not recognized as an internal or external command", but when I do so with admin privileges' it works fine.
I looked at this thread and attempted to add the pthread.dll file to my system but this seemed to just make the program run worse as admin. I'm confused why something that should be so basic as setting up a programming language is giving me so much headache
Ok, managed to fix it by making an environment variable directly to my C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.10.3\bin location.
I thought making an environment variable to C:\ProgramData\chocolatey\ would have been sufficient but clearly not. Weird too as Chocolatey added many of its own environment variables but not one that pointed to gchi

Go back and forth between environments in a script (e.g., Jupyter Notebooks)

I'm very confused in regards to whether it's possible to switch between environments in one script. I'm currently working Jupyter Notebooks and realized I do need a package that is in a separate (non-root) environment and would like to be able to import/use it. I initially tried to just load it into my root env, but it has so many conflicts, it's not possible. So trying to switch env mid script- is this not possible without going through hoops and going through Anaconda prompt? I've looked at about 30 articles and/or stackoverflow pages and it seems like my only option is to add my environment to the default sys.path within Jupyter OR potentially create another environment that contains both environment packages. This suggestion was unclear...not sure how to run this and I don't want to run through a shell/prompt either.
These were good resources:
RealPython: On Virtual Envs
StackOverflow: In which conda env is Jupyter executing?
Any clarity I can get on the topic for someone who doesn't understand this well, would be appreciated (Please explain as if I'm a Level 0/Beginner).
Now I'm looking back on this old post, thought I'd answer it since it never got an answer. While it's extremely frustrating to realize that needed packages don't mesh together mid-project, for each significant project, a new environment should be created. I still have a general environment that I use for minor projects, but for situations like this, I use anaconda's cheat sheet to make sure that in the new environment I'm creating, packages will all sync together by specifying versions directly in the creation in the environment. Also, getting comfortable with creating/copying .yml files and loading them directly into conda have also been helpful.
conda env create --file envname.yml
Once that's done, if I'm using jupyter notebooks, making sure it's been established as a kernel has been important.
Of course, if you're using an IDE like pycharm, you can bypass the conda prompt (pycharm is still talking to conda), which is sometimes just easier if you're on a deadline rather than going back and forth between different software.

Python was not found but can be installed

I have just installed python3.8 and sublime text editor. I am attempting to run the python build on sublime text but I am met with "Python was not found but can be installed" error.
Both python and sublime are installed on E:\
When opening cmd prompt I can change dir and am able to run py from there without an issue.
I'm assuming that my sublime is not pointing to the correct dir but don't know how to resolve this issue.
This isn't a Sublime issue, it's a Windows 10 issue. My Windows 10 boxes don't have this feature so I'm not sure how widely spread it is, but you may want to check out this (seemingly unrelated) question "Permission Denied" trying to run Python on Windows 10.
The general gist from this post is that these new stub redirectors are supposed to direct you into installing some missing applications from the Windows App store and that user-installed versions are supposed to take priority, but depending on how the PATH is modified the system might find the stub versions before your user installed versions.
The currently accepted answer mentions:
The second part of correcting it is to type "manage app execution aliases" into the Windows search prompt and disable the store versions of Python altogether.
It's possible that you'll only need to do the second part, but on my system I made both changes and everything is back to normal now.
In the comments, there are comments from Zooba which further indicate that this is the way to go:
(Microsoft employee and CPython core developer here) You definitely only need to do the second part. There have been a couple of bugs related to upgrading apps resetting aliases which will be fixed in the next stable update, so it should be a one-time fix by then. While you're getting Insiders updates you may need to do it a couple more times.
... And launching the Store is a new feature to help people install Python - if you've added it to PATH using the regular installer it should take precedence over the new redirector, but if not you've discovered above how to disable it.
i had the same problem, so i went to the microsoft store (windos 10) and simply installed "python 3.9" and problem was gone!
sorry for bad english btw

how to use environment variables in vscode settings json

I want to be able to use linux environment variables in vscode workspace settings (specifically $HOME) so that I can specify paths that aren't specific to a user. In this case I am trying to set the java.home setting.
I have tried using ${env:HOME} but this doesn't seem to work. I suspect this is only for vscode tasks.
{
"java.home": "${env:HOME}/.sdkman/candidates/java/8.0.222.hs-adpt/"
}
Get the following error message at the moment:
The java.home variable defined in VS Code settings points to a missing or inaccessible folder (${env:HOME}/.sdkman/candidates/java/8.0.222.hs-adpt/)
Environment variables in Linux are supported now in VSCode (although I don't know since when or which version exactly). I have VSCode for Linux 1.73.1.
You can now use the following (just like in the question above):
{
"java.home": "${env:HOME}/.sdkman/candidates/java/8.0.222.hs-adpt/"
}

JupyterLab User Settings File

I leverage Docker containers to launch JupyterLabs and would like the ability to apply user settings directly at launch, instead of configuring user settings through the "Advanced Settings Editor" GUI at every container launch.
In reviewing the following pull request, it does seem that this functionality should exist: https://github.com/jupyterlab/jupyterlab/pull/2585
I have not found anything referencing this capability in the JupyterLab documentation, so any leads would be greatly appreciated!
Running jupyter-lab --generate-config should generate a config file in /home/<USER>/.jupyter/jupyter_notebook_config.py
Settings for extensions are documented here:
https://jupyterlab.readthedocs.io/en/stable/user/extensions.html#settings
In short, you can supply and overrides.json in <sys-prefix>/share/jupyter/lab/settings where <sys-prefix> can be found by running jupyter lab path.
The example from the docs shows an overrides.json like this:
{
"#jupyterlab/apputils-extension:themes": {
"theme": "JupyterLab Dark"
}
}
I couldn't find any documentations, however in your folder ~/.jupyter/lab/user-settings/#jupyterlab if you create a custom notebook configuration (for instance), you will have a file created in notebook-extension/tracker.jupyterlab-settings.
You can copy the folder(s) you want to use for each of your container in this location, then when you start a jupyter lab, you should see the custom configuration(s) loaded correctly.
In /usr/local/share/jupyter/lab/schemas/#jupyterlab, you can find all default settings.
And in notebook-extension/tracker.json, you can find the recordTiming.
Change the default value will help.

Resources