"mkvirtualenv command not found" within vagrantbox - python

I am trying to set up a django project using vagrant, but I am getting this error:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-112-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
0 packages can be updated.
0 updates are security updates.
Last login: Sun Jan 28 08:21:28 2018 from 10.0.2.2
vagrant#ubuntu-xenial:~$ mkvirtualenv profiles_api --python=python3
mkvirtualenv: command not found
In my vagrant file I have the following :
sudo pip install virtualenvwrapper
if ! grep -q VIRTUALENV_ALREADY_ADDED /home/ubuntu/.bashrc; then
echo "# VIRTUALENV_ALREADY_ADDED" >> /home/ubuntu/.bashrc
echo "WORKON_HOME=~/.virtualenvs" >> /home/ubuntu/.bashrc
echo "PROJECT_HOME=/vagrant" >> /home/ubuntu/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> /home/ubuntu/.bashrc
fi
I have python 3.6,3.5 and anaconda installed, if that matters. Thank you for the help

Try this code in terminal when you entered into vagrant
export WORKON_HOME=~/Envs
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh
you have to change the path of file

First of all destroy the vagrant box by running following command:
vagrant destroy
Change your vagrant file to this:
sudo pip install virtualenvwrapper
if ! grep -q VIRTUALENV_ALREADY_ADDED /home/vagrant/.bashrc; then
echo "# VIRTUALENV_ALREADY_ADDED" >> /home/vagrant/.bashrc
echo "WORKON_HOME=~/.virtualenvs" >> /home/vagrant/.bashrc
echo "PROJECT_HOME=/vagrant" >> /home/vagrant/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> /home/vagrant/.bashrc
fi
Now initialize your vagrant box with vagrant init command and then run vagrant up command.

Related

Python & Wxpython | This program needs access to the screen?

Goal: Use ESPHome Flasher https://github.com/esphome/esphome-flasher
TLDR: Starting esphomeflasher I get this error message:
This program needs access to the screen. Please run with a
Framework build of python, and only when you are logged in
on the main display of your Mac.
Python Setup: https://opensource.com/article/19/5/python-3-default-mac
Mac Setup: Fresh Catalina installation.
Steps:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install pyenv
pyenv install 3.9.1
pyenv global 3.9.1
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
pip install --upgrade pip
Install esphomeflasher: https://github.com/esphome/esphome-flasher
Steps:
pip3 install wxpython
pip3 install esphomeflasher
Problem:
Starting esphomeflasher I get the following error:
This program needs access to the screen. Please run with a
Framework build of python, and only when you are logged in
on the main display of your Mac.
I found this but don't know how to apply it in my case.
https://blurringexistence.net/wxpython-using-virtualenvwrapper-on-osx.html
My .zshrc config:
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
PATH=$(pyenv root)/shims:$PATH
# We want to regularly go to our virtual environment directory
echo 'export WORKON_HOME=~/.virtualenvs' >> .zshrc
# If in a given virtual environment, make a virtual environment directory
# If one does not already exist
echo 'mkdir -p $WORKON_HOME' >> .zshrc
# Activate the new virtual environment by calling this script
# Note that $USER will substitute for your current user
echo '. ~/.pyenv/versions/3.9.1/bin/virtualenvwrapper.sh' >> .bash_profile
export WORKON_HOME=~/.virtualenvs
mkdir -p $WORKON_HOME
export WORKON_HOME=~/.virtualenvs
mkdir -p $WORKON_HOME

How to activate an Anaconda environment in a Singularity recipe

I am trying to create a singularity image and recipe that will create an anaconda environment and then activate said environment so I can build the python wheel of a project in that environment so it's 100% installed and functional after the singularity build is completed.
Bootstrap: docker
From: nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04
%environment
# use bash as default shell
SHELL=/bin/bash
# add CUDA paths
CPATH="/usr/local/cuda/include:$CPATH"
PATH="/usr/local/cuda/bin:$PATH"
LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
CUDA_HOME="/usr/local/cuda"
# add Anaconda path
PATH="/usr/local/anaconda3/bin:$PATH"
export PATH LD_LIBRARY_PATH CPATH CUDA_HOME
export MKL_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1
%setup
# runs on host
# the path to the image is $SINGULARITY_ROOTFS
%post
# post-setup script
# load environment variables
. /environment
# use bash as default shell
echo "\n #Using bash as default shell \n" >> /environment
echo 'SHELL=/bin/bash' >> /environment
# make environment file executable
chmod +x /environment
# default mount paths
mkdir /scratch /data
#Add CUDA paths
echo "\n #Cuda paths \n" >> /environment
echo 'export CPATH="/usr/local/cuda/include:$CPATH"' >> /environment
echo 'export PATH="/usr/local/cuda/bin:$PATH"' >> /environment
echo 'export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"' >> /environment
echo 'export CUDA_HOME="/usr/local/cuda"' >> /environment
# updating and getting required packages
apt-get update
apt-get install -y wget git vim build-essential cmake
# creates a build directory
mkdir build
cd build
# download and install Anaconda
CONDA_INSTALL_PATH="/usr/local/anaconda3"
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
chmod +x Anaconda3-5.0.1-Linux-x86_64.sh
./Anaconda3-5.0.1-Linux-x86_64.sh -b -p $CONDA_INSTALL_PATH
# download and install CaImAn
git clone https://github.com/flatironinstitute/CaImAn.git
cd CaImAn
conda env create -n caiman -f environment.yml
source activate caiman
pip install .
caimanmanager.py install
source deactivate
%runscript
# executes with the singularity run command
# delete this section to use existing docker ENTRYPOINT command
%test
# test that script is a success
I've tried both conda activate and source activate and get the same error for both.
+ source activate caiman
/bin/sh: 41: source: not found
ABORT: Aborting with RETVAL=255
Cleaning up...
Is this just something I have to do afterwards by making the image writable?
That would be the next default solution, but it would be nice if the recipe could just work.
*Edit 1
. activate caiman returns.
+ . activate caiman
+ [[ -n ]]
/bin/sh: 4: /usr/local/anaconda3/bin/activate: [[: not found
+ [[ -n ]]
/bin/sh: 7: /usr/local/anaconda3/bin/activate: [[: not found
+ echo Only bash and zsh are supported
Only bash and zsh are supported
+ return 1
ABORT: Aborting with RETVAL=255
Cleaning up...
*Edit 2
By using a newer version of Anaconda, the not found error goes away. All I did was change the Anaconda distribution I got with wget, and I also forced and update just to be doubly sure.
# download and install Anaconda
CONDA_INSTALL_PATH="/usr/local/anaconda3"
wget https://repo.continuum.io/archive/Anaconda3-5.3.1-Linux-x86_64.sh
chmod +x Anaconda3-5.3.1-Linux-x86_64.sh
./Anaconda3-5.3.1-Linux-x86_64.sh -b -p $CONDA_INSTALL_PATH
conda update -n base -c defaults conda
pip install --upgrade pip
If I am not wrong (which is totally possible) the same happens with virtualenv.
The problem is source is not a command, try:
. activate caiman
instead of
source activate caiman
Editing after updated question, check this https://github.com/conda/conda/issues/6639 you might want to investigate what your activate is doing (seems to be looking for non existing files)

how can I find the path of virtualenv python

how can I find the path of virtualenv python ,built with this tutorial?
(i want to find python in this env and use it in my eclipse)
$ sudo pip install virtualenv virtualenvwrapper
$ export WORKON_HOME=$HOME/.virtualenvs
$ source /usr/local/bin/virtualenvwrapper.sh
$ echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.bashrc
$ echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
$ echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
$ source ~/.bashrc
$ mkvirtualenv cv -p python3
You can use which to find out which binary will be executed...
For example:
$ which python3
/home/attie/projects/thing/venv/bin/python3
By default it just shows the first match, but you can give the -a argument to show all:
$ which -a python3
/home/attie/projects/thing/venv/bin/python3
/usr/bin/python3
There is VIRTUAL_ENV system variable already set with the path.
Check <your_venv>/bin/activate (which is a simple script) to see how the virtual env is setup in general, but this variable will give you the clean path already:
echo $VIRTUAL_ENV
<full virtual env path>
mkvirtualenv creates virtualenvs in $WORKON_HOME, that is your virtualenv is in $HOME/.virtualenvs/cv/.

Setup VM with virtualenv with a shell script

So I'm trying to streamline my deployment process. I have a VM with Vagrant (Ubuntu Vivid64, virtualenv, django and postgres), but I still have to execute a lot of commands after executing vagrant up. I've used this vagrantfile: https://github.com/FlipperPA/django-python3-vagrant
This gets executed through the Vagrant provision script:
sudo apt-get -qq install git python3-pip > /dev/null 2>&1
sudo pip3 install --quiet virtualenv
sudo pip3 install --quiet virtualenvwrapper
mkdir ~vagrant/.virtualenvs
chown vagrant:vagrant ~vagrant/.virtualenvs
printf "\n\n# Virtualenv settings\n" >> ~vagrant/.bashrc
printf "export PYTHONPATH=/usr/lib/python3.4" >> ~vagrant/.bashrc
printf "export WORKON_HOME=~vagrant/.virtualenvs\n" >> ~vagrant/.bashrc
printf "export PROJECT_HOME=/vagrant\n" >> ~vagrant/.bashrc
printf "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.4\n" >> ~vagrant/.bashrc
printf "source /usr/local/bin/virtualenvwrapper.sh\n" >> ~vagrant/.bashrc
printf "alias python='/usr/bin/python3.4'\n" >> ~vagrant/.bashrc
When this is finished, I want to create a new virtualenv and install django in it. Then I want to install postgres and the related packages, create the database for postgres and then install a Python package for the postgres connection. This is the shell script I came up with:
#!/bin/bash
sudo apt-get update
# Setup virtual environment for Django
mkvirtualenv vms_django
pip3 install django
# Setup Postgres
sudo apt-get install libpq-dev postgresql postgresql-contrib
sudo su Postgres
psql postgres -c "CREATE DATABASE djangodb;
CREATE USER hhhhh WITH PASSWORD 'root';
ALTER ROLE hhhhh SET client_encoding TO 'utf8';
ALTER ROLE hhhhh SET default_transaction_isolation TO 'read committed';
ALTER ROLE hhhhh SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE djangodb TO hhhhh;"
exit
# Setup Postgres Django connection
pip3 install psycopg2
# Migrate DB
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser
...but that doesn't work. mkvirtualenv and psql commands are not found, and the last three python commands throw importerrors: No module named 'psycopg2'.
Anyone able to lend a hand? Alternative ways to solve my problem are welcome too.

Setting virtualenv to use a compiled from source python as bin

I need to force a virtualenv to use a compiled source python on my ci server (long story short: travis ci support python 2.7.3. heroku works with 2.7.6 and we insist on testing in the same environment as production) . But I fail to get virtualenv to run against it.
travis first runs this script:
if [ ! -d ./compiled ]; then
echo "creating compiled folder"
mkdir compiled
else
echo "compiled exists"
fi
cd compiled
if [ ! -e Python-2.7.6.tar.xz ]; then
echo "Downloading python and compiling"
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure
make
chmod +x ./python
else
echo "Compiled python exists!"
fi
and then:
- virtualenv -p ./python ./compiled/python276
- source ./compiled/python276/bin/activate
but when then doing python --version shows 2.7.3 instead of 2.7.6
Guess I'm missing something, Thanks for the help!
Go to the virtualenv folder, and open bin/ folder:
~/.Virtualenv/my_project/bin
Remove 'python' file, and create a symbolic link to the python executable, that you want to use, like:
cd ~/.Virtualenv/my_project/bin
mv python python-bkp
ln -s /usr/bin/python .

Categories

Resources