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
Related
I use pyenv (installed with homebrew) to manage my macOS python-versions.
Python 3.11 just came out, but pyenv doesn't see this version. However from googling it appears others are able to see/install it.
How to fix?
This caused me some trouble, so I'm gona jot my solution down in case it's useful (and in case others can improve upon the solution path).
EDIT: On a fresh macOS, I bumped into: UserWarning: Could not import the lzma module. Your installed Python is incomplete and (as per answers there) did brew install xz before pyenv install 3.11.0.
The first issue was that the homebrew-installed pyenv doesn't see the new 3.11. So I had to uninstall it and re-install using pyenv's recommended method:
> brew uninstall pyenv
> # rm -rf ~/.pyenv
> curl https://pyenv.run | bash
> pyenv install 3.11.0
> pyenv global 3.11.0
> which python ; python --version # sanity check
(Note: You'll lose your current .pyenv-s if you rm -rf ~/.pyenv -- I did it to keep things simple but don't know if it's needed)
Now to test it out:
> python -m venv --upgrade-deps .venv
> which python ; which pip
So far so good, but if I create a foo.py that does import requests, and:
> pip install requests
> python foo.py
... I get "ModuleNotFoundError: No module named 'requests'"
Which is confusing.
An engineer suggested I inspect python -m site but I lost the original output.
Next I see at the bottom of my ~/.bash_profile:
# recommendation by homebrew from `brew install pyenv`
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Now I'm pretty sure the last time I installed pyenv (using homebrew) it suggested this, so I copy+pasted it into my ~/.bash_profile.
But it turns out I needed an additional:
eval "$(pyenv init --path)"
Now I restart my terminal and boom it works.
> pyenv init --path
PATH="$(bash --norc -ec 'IFS=:; paths=($PATH); for i in ${!paths[#]}; do if [[ ${paths[i]} == "'/Users/pi/.pyenv/shims'" ]]; then unset '\''paths[i]'\''; fi; done; echo "${paths[*]}"')"
export PATH="/Users/pi/.pyenv/shims:${PATH}"
command pyenv rehash 2>/dev/null
This appears to be removing any pyenv shims from the PATH env-var and prepending the correct shim to the PATH.
Now what about the original pyenv init - command? What does that do?
> pyenv init -
PATH="$(bash --norc -ec 'IFS=:; paths=($PATH); for i in ${!paths[#]}; do if [[ ${paths[i]} == "'/Users/pi/.pyenv/shims'" ]]; then unset '\''paths[i]'\''; fi; done; echo "${paths[*]}"')"
export PATH="/Users/pi/.pyenv/shims:${PATH}"
export PYENV_SHELL=bash
source '/Users/pi/.pyenv/libexec/../completions/pyenv.bash'
command pyenv rehash 2>/dev/null
pyenv() {
local command
command="${1:-}"
if [ "$#" -gt 0 ]; then
shift
fi
case "$command" in
activate|deactivate|rehash|shell)
eval "$(pyenv "sh-$command" "$#")"
;;
*)
command pyenv "$command" "$#"
;;
esac
}
This all seems confusing. The above is documented in https://github.com/pyenv/pyenv#advanced-configuration but do I really need such a complex path to achieve something that feels like it should be 'out-of-the-box'?
I have pyenv installed and have downloaded python versions 3.6.15 and 3.7.12. When I run
pyenv global 3.7.12
python -V
the output is: Python 3.10.2
pyenv versions gives the output
system
3.6.15
* 3.7.12 (set by /home/frege/.pyenv/version)
$ echo $PYENV_ROOT: /home/frege/.pyenv
$ which python: /user/bin/python
$ type python: python is hashed (/usr/bin/python)
I have the following in my .bashrc
export PATH="${HOME}/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
I have restarted my terminal and $PATH contains
/home/frege/.pyenv/plugins/pyenv-virtualenv/shims:
/home/frege/.pyenv/bin:
...
/usr/bin:
What is wrong?
I understand that getting pyenv and virtualenvs to work together can be problematic. I came from virtualenvwrapper which makes working on virtual envs simple and I found pyenv a bit of a culture shock.
I have finally got my workflow sorted and I thought I would post it here as it might help someone. My OS is Manjaro.
I installed pyenv:
curl https://pyenv.run | bash
The following was added to .bashrc:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:${PATH}"
export PATH="$PYENV_ROOT/bin:$PATH"
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
export WORKON_HOME=$HOME/.virtualenvs
eval "$(pyenv init -)"
pyenv virtualenvwrapper_lazy
(I have not seen the line export PATH="$PYENV_ROOT/shims:${PATH}" in many explanations, but it is critical in mine.)
To invoke a global version of python:
pyenv shell <version>
or
pyenv shell system
To create a virtual env:
pyenv virtualenv <version> <env name>
To activate the virtual environment:
pyenv activate <env name>
To deactivate the virtual environment:
source deactivate
I already referred to this related post
I am currently using a jupyter notebook in my server (where I don't have sudo access) which has python 2.7 kernel.
However, I would like to add Python >= 3.5 as the kernel. So, I was using followed the tutorial to install Pyenv.
The installation is successful and I get the below message in my jupyter notebook
WARNING: seems you still have not added 'pyenv' to the load path.
# Load pyenv automatically by adding
# the following to ~/.bashrc:
export PATH="/home/abcd/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Later, when I try to execute the below command, I get an error as shown below
!pyenv install --list | grep " 3\.[678]"
Please note that I am using ! symbol as I am executing it from Jupyter notebook cell
/bin/sh: 1: pyenv: not found
How can I avoid this error and make pyenv work and produce the below output
As per the discussion in comments section, it turns out the pyenv path wasn't exported to .bashrc. It can be done by executing the following commands in terminal:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
then restart the shell
exec "$SHELL"
Now, you can use pyenv to create virtual environments, then activate the environment and start working without interfering with the system environment.
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 ,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/.