mkvirtualenv in current directory (windows) - virtual-environment

I am working on a Windows (10) environment using command prompt. I created a project directory here c:\users\myproject. In command prompt, I type
C:\users\myproject>mkvirtualenv myenv .
virtuanenv "." already exists
If I leave out the "." at the end of the command, it creates a virtual environment in C:\users\Envs\ directory.
How do I create a virtual environment in my project directory itself?

You have to set the WORKON_HOME environment variable name and value.
The name is simply: WORKON_HOME
The value is the path where you want your virtual env directory to be created when you type mkvirtualenv venv
"venv" above is nothing special; it's just a name you choose. If you don't specify the WORKON_HOME variable, when you run mkvirtualenv venv on Windows, a directory named %USERPROFILE%\Envs where %USERPROFILE% translates to C:\Users\your.name.
See my more verbose, step-by-step answer here.

On Linux and MacOS I use the following command:
mkvirtualenv -a [full path to directory] [name of project]
I am not sure if this is the same for Windows but please give it a try and let me know.
In your example it would be:
mkvirtualenv -a C:\users\myproject myenv

Related

Why can't I run a python command via a powershell script?

I have a powershell script which is meant to create a virtual environment with the following command:
py -3.6 -m venv --clear env
I have verified that I can do this when I run the above command in a powershell window, and the environment is created. However when I run the powershell script via an azure release pipeline, I get the following error:
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I have verified that my user PATH environment variable has all the necessary paths:
C:\Python36\Scripts\;C:\Python36\;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Python36\Lib\site-packages\pywin32_system32;C:\Python36\Lib\site-packages\win32;C:\Automation\app\env\Scripts;C:\Python38;C:\Python38\Scripts;C:\Python38\Lib\site-packages\win32;C:\Python38\Lib\site-packages\pywin32_system32
Specs:
Python: 3.6.7
OS: Windows 10
Environment: Azure virtual machine.
Any help would be much appreciated.
There seems to be a change when the variable is injected into the pipeline.
Try using:
PYTHON -3_6 -M VENV --clear ENV
Environment variables:
Environment variables are specific to the operating system you are using. They are injected into a pipeline in platform-specific ways. The format corresponds to how environment variables get formatted for your specific scripting platform.
On UNIX systems (macOS and Linux), environment variables have the format $NAME. On Windows, the format is %NAME% for batch and $env:NAME in PowerShell.
System and user-defined variables also get injected as environment variables for your platform. When variables are turned into environment variables, variable names become uppercase, and periods turn into underscores. For example, the variable name any.variable becomes the variable name $ANY_VARIABLE.
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#environment-variables
It runs out I hadn't added the paths to the system variables (in windows there are user environment variables and system environment variables, and pywin32 uses the system ones.

Where is the command “conda” (Executable file in Anaconda ?

I do not add anaconda3/bin into my $PATH variable in ubuntu(run which conda return null).
I also can use conda -V and conda -h in another directory.
Of course, the executable file conda in anaconda3/bin also works.
but another command like jupyter only works we are in the following directory anaconda3/bin.
I'm puzzled about it, the issue seems to be the environmental variable, I don't know how to fix it, any help is appreciated.
Add the anaconda path to the bash
cd ~
gedit .bashrc
export PATH=~/anaconda3/bin:$PATH

Activate virtualenv using alias

I can activate my python virtual environment from it's folder by entering . bin/activate. I'd like to instead type a single word alias, such as shazam, from the home folder (or anywhere else) that activates the environment, changes to my master project folder, and lists my projects.
I tried creating an alias in .bashrc that pointed to an .sh file containing:
cd ~/path-to-virtual-environment
. bin/activate
cd ~/path-to-master-project-folder
ls -a
I was getting a permission denied error, so I ran chmod u+x <script file>. The script now runs, but the VE does not activate and while the project folders are listed, the shell is not in the master project folder. I would appreciate some guidance. Thanks.
Recreate all your environments in ~/.virtualenvs and install virtualenvwrapper. The command to activate an env is workon shazam. Command line completion is supported.
Now about your problem: you've tried to activate an environment in a shell script. That doesn't work because shell scripts run with another shell and env activation change their environments, not the current. I.e., the environment briefly activated but then at the end of the script the new shell exits and the environment deactivated.
There are two ways to overcome this.
Use aliases or shell functions instead of scripts — they are the only way to change the current shell's environment.
Run interactive shell at the end of your script (exec $SHELL). It inherits activated environment and gives you a command prompt. To deactivate simply exit the shell (exit or [Ctrl]+[D].).

The $PATH variable does not change after installing DB2 in openSUSE

I try to install DB2 in openSUSE.(success in Centos)
After installation the $PATH does not change and I can't use db2start, db2set commands.
I don't know the $PATH for DB2.
The openSUSE version: leap-42.1
The DB2 batabase version: V9.7x64
Here is my $PATH:
echo $PATH
/home/mylinux/bin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin/X11:/usr/games
DB2-specific environment variables are set by the db2profile script that is installed in the directory called sqllib in the instance home. You need to execute (source) this script to set the variables in your shell session:
$ source /home/db2inst1/sqllib/db2profile
You can also add execution of the profile to your shell .profile.

Issue with $PYTHONPATH

I get the following message when trying to run virtualenv . --no-site-packages
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/
and your PYTHONPATH environment variable currently contains:
''
However, when I echo my PYTHONPATH, I see the path from the default setting:
/usr/local/python-3.3.1/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/:/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/
So my PYTHONPATH does contain the directory I am installing to.
Anyone have any ideas what is going on?
Turns out I needed to use virtualenv-3.3, not virtualenv.

Resources