virtualenvwrapper commands aren't working - virtualenvwrapper

tow-81-235:Projects pessimisticoptimism$ mkvirtualenv development
-bash: mkvirtualenv: command not found
tow-81-235:Projects pessimisticoptimism$ sudo pip install virtualenvwrapper
Password:
Requirement already satisfied (use --upgrade to upgrade): virtualenvwrapper in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Python/2.7/site-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): virtualenv-clone in /Library/Python/2.7/site-packages (from virtualenvwrapper)
Cleaning up...
tow-81-235:Projects pessimisticoptimism$ mkvirtualenv development
-bash: mkvirtualenv: command not found
Why am I getting this error? I have virtualenv and virtualenvwrapper installed. I'd like to use mkvirtualenv and workon. I find it odd that virtualenv is working, but virtualenvwrapper isn't.

1st, ensure you're installing with sudo:
sudo pip install virtualenvwrapper
2nd, append the following lines to your .bashrc file (with nano ~/.bashrc):
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
3rd, reload your profile
source ~/.bashrc

Summary
I'm on a Mac and my answer is similar to #Ramces answer except it was with bash_profile. I just want to elaborate a little further for Mac users to be aware that there's a lot of different profiles including:
.bashrc
.bash_profile
.profile
Some files like .profile do not take precedence over .bash_profile (if it exists) and will then be ignored. If you successfully do the below steps and get a virtual env working, but then close out your terminal and 'workon command not found', then you need to setup for the correct profile. For a detailed answer, see here
Install Steps:
sudo pip install virtualenv
Installs virtualenv (allows you to separate your envrionments)
sudo pip install virtualenvwrapper
Installs virtualenvwrapper (allows you to use the 'workon' command)
nano ~/.bash_profile
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bash_profile
Reloads the profile. Going forward you only need step 5 (to create new environments) and step 6 (to run environments)
mkvirtualenv my_env
This creates your virtual environment (this example is with 'my_env')
workon my_env
This lets you work on a specific environment (this example is with 'my_env')

After installing the virtualenvwrapper package using pip, you also have to do some initialisation/set your preferences. See the introduction in the virtualenvwrapper docs.
Most relevant for finding the commands should be sourcing the virtualenvwrapper script into your shell. In the docs it is mentioned as
$ source /usr/local/bin/virtualenvwrapper.sh
You still have to adjust the path to your setup. My guess for your Mac would be:
$ source /Library/Python/2.7/site-packages/virtualenvwrapper.sh

Simple process
sudo apt-get install python-pip(if pip is not installed)
sudo pip install virtualenv
Create a dir to store your virtualenvs
mkdir ~/.virtualenvs
sudo pip install virtualenvwrapper
Run following command
export WORKON_HOME=~/.virtualenvs
Add virtualenvwrapper.sh to .bashrc
Add this line to the end of ~/.bashrc so that the virtualenvwrapper commands are loaded.
. /usr/local/bin/virtualenvwrapper.sh
you will find .bashrc.sh file in home directory by doing ctrl+h. if not then use find command to find .bashrc.sh "file ls -la ~/ | more"
Hit this command
source /usr/local/bin/virtualenvwrapper.sh
Hit this command
source ~/.bashrc

It sounds like you have multiple Python installations on your machine and virtualenvwrapper is not pointing to the right Python.
Find out which Python virtualenvwrapper is using. You get a hint where to look with which virtualenvwrapper.sh (In this case /usr/local/bin):
> /usr/local/bin/virtualenvwrapper.sh
If you don't get any return here make sure you use the correct pip when installing. The pip command might link to a different Python then you expect. Check your usr/local/bin directory for pip links (pip, pip2, pip2.7, pip3, pip3.5). It is easy to get system pip, pip2 and pip2.7 mixed up.
After you have found the Python location, add/update all paths in your .profile:
export WORKON_HOME=$HOME/venv
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2
source /usr/local/bin/virtualenvwrapper.sh
Finally reload your profile: source ~/.profile

I am on Mac OS X 10.9.2 and for me virtualenvwrapper.sh file was present in
/usr/local/bin/virtualenvwrapper.sh
So I simply copied this into ~/.profile file:
source /usr/local/bin/virtualenvwrapper.sh
And now my ~/.profile file looks something like this:
# MacPorts Installer addition on 2014-02-23_at_17:28:39: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
source /usr/local/bin/virtualenvwrapper.sh
And now I am able to use virtualenvwrapper commands without any issue whatsoever

Users of the Anaconda (from Continuum) distribution of Python should note that
sudo pip install virtualenvwrapper
will be anaconda-aware. So if you
which python
that should give you an idea of where to point your virtualenv in your .bashrc and/or .profile configuration files.

Related

Install conda package from Google Datalab

I'm looking to use the ospc taxcalc package in a Google Datalab notebook. This package must be installed via conda.
Datalab doesn't have conda by default, so this method (from https://stackoverflow.com/a/33176085/1840471) fails:
%%bash
conda install -c ospc taxcalc
Installing via pip also doesn't work:
%%bash
pip install conda
conda install -c ospc taxcalc
ERROR: The install method you used for conda--probably either pip install conda or easy_install conda--is not compatible with using conda as an application. If your intention is to install conda as a standalone application, currently supported install methods include the Anaconda installer and the miniconda installer. You can download the miniconda installer from https://conda.io/miniconda.html.
Following that URL, I tried this:
%%bash
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
bash Miniconda2-latest-Linux-x86_64.sh
wget works, but the bash command to install just kept in "Running..." state for seeming perpetuity.
This seems to be due to the conda installer prompting for several Enter keystrokes to review the license, and then for a yes indicating acceptance of the license terms. So conda's silent mode installation looked promising:
%%bash
bash Miniconda2-latest-Linux-x86_64.sh -u -b -p $HOME/miniconda
This produced the following warning:
WARNING: You currently have a PYTHONPATH environment variable set. This may cause unexpected behavior when running the Python interpreter in Miniconda2. For best results, please verify that your PYTHONPATH only points to directories of packages that are compatible with the Python interpreter in Miniconda2: /content/miniconda
And doesn't make available the conda command:
%%bash
conda install -c ospc taxcalc
bash: line 1: conda: command not found
There is a pending github issue tracking this work - https://github.com/googledatalab/datalab/issues/1376
I believe we will need to install conda and use that for python, pip and all other python packages, and in the interim it may not be possible to mix the two python environments. However someone with more experience with conda might know otherwise.
As of the 2018-02-21 release, Datalab supports Conda and kernels are each in their own Conda environment.

How to install nano using GitBash in Windows 10?

I am trying to install nano editor. From all the previous posts, I am stuck on path. What is path? How do I fix put my path?
I have:
$ mv nano ~/path/to/git/share
$ nano abc
bash: nano: command not found
You can add it via chocolatey.
choco install nano
PATH is the environment variable which is used to locate an executable you want to run.
See "How to permanently set $PATH on Linux?": you can add the folder where nano is in your .bashrc (which you can create directly under %USERPROFILE%, used by Git bash as $HOME)
Add to ~/.bashrc:
export PATH=$PATH:~/path/to/git/share
Then type
source ~/.bashrc
If you don't want to add it to your PATH, you can follow this step-by-step procedure, which does include the installation of nano-git-0d9a7347243.exe.
If your ultimate goal is to have and use nano on Windows 10, you can download the nano installer from here and just install the .msi file the usual Windows way. No manual path configurations required.

There is no activate when I am trying to run my virtual env

1) I installed virtualenv using pip.
2) I ran the command virtualenv venv
3) Then I ran source venv/bin/activate but it says that there is no such file or directory.
When I cd into venv/bin I find 3 things - python, python 2.7, and python 3.5. Does anyone know the problem?
i have had the same problem. and what i did is just run the command
virtualenv env
again. And then more files were generated under directory env/bin, including the activate file. it's so weird.
I solved the similar problem running python3.7 -m venv venv, you can change for your version of python that is installed in your enviroment.
According to Python doc, the installation step is
$ python3 -m pip install --user virtualenv
$ python3 -m venv env
The last command gives a warning message,
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
$ sudo apt-get install python3-venv
Now, activate is available.
I solved a similar problem by naming it venv2 when I ran virtualenv. I already had a virtual environment named venv for another project. This allowed me to proceed.
I experienced this problem when using the --upgrade option. Removed the option, and all ran as expected.
I double it is caused by some networking issue, I run it twice to get 'activate' script installed. Maybe first it can't connect to some source so it just abort installation.
I had this happen on rasbian when I hadn't installed python3-pip before creating the venv.

Installing with PIP in virtualenv?

I'm trying to wrap my head around virtualenv and pip still.
If I use pip to install a library, it doesn't matter where I 'cd' to, because it installs the libraries in the same place right (which i dont even know where that is)? So I guess my question is, when I install something with pip, how do I make sure it only installs that library inside of my virtual environment? Do I need to cd to that directory first? or is there a command I'm supposed to use with pip to make sure it only installs to the virtualenv project I'm working in?
Activate virtualenv first:
source virt_name/bin/activate
Then after that, install the libraries:
pip install module_name
Note: Don't use sudo with pip because sometimes it will assume you want to install in /usr/local/lib/site-packages.
Generally speaking, if you do not use virtualenv --system-site-packages to create your virtualenv, you should be only working with your per-environment packages.
Providing you run the activate script before installing anything.
i.e. Do the following, if you want to install something in your virtualenv.
Run activate script
Windows: [ve_directory]\Script\activate.bat
Linux: source [ve_directory]/bin/activate
pip install [your requirements]
I think it doesn't matter where your current working directory is.
Reference:
http://www.virtualenv.org/en/latest/#the-system-site-packages-option
When you create a new environment with virtualenv, among other things it creates a bash script venv/bin/activate (where venv is the folder you specified when you created the environment; libraries are located there as well, by the way). When you run it in your shell the environment variables become arranged so that pip installs new libraries in this environment's folder. See virtualenv docs for details, section "activate script".

Where is mongoctl after installation?

I've installed mongoctl according to Mongolab's simple instructions, but I can't do anything with the installed package because which mongoctl resolves to nothing.
The site makes it look like pip installs some kind of command line tool, but it seems like it just installs the python package, which would be fine if all of the documentation didn't treat mongoctl as a command line tool.
What's going on?
You can add the following option to your install command to ensure that "mongoctl" exe goes to /usr/local/bin
--install-option="--install-scripts=/usr/local/bin"
Since mongoctl is already installed on your mac, you will probably need to add a --upgrade and a --force-reinstall
So try the following
sudo pip install mongoctl --install-option="--install-scripts=/usr/local/bin" --upgrade --force-reinstall
What OS are you using?
'mongoctl' should be in /usr/local/bin. Check to make sure that directory is in your PATH
-will