The shortest memo for building a python environment that takes less than 5 minutes to work.

Python is already on the mac, and I felt like I was doing it, but it's not. There are many situations where you need to switch between 2 and 3 in python. If you want to do python, you can create a conda environment. I don't use virtualenv or docker or anything like that. Only conda from pyenv is used here. conda is enough.

Put pyenv

ubuntu


git clone https://github.com/yyuu/pyenv.git ~/.pyenv

mac


brew install pyenv

win doesn't need pyenv. To conda.

Through pyenv

ubuntu

bashrc


#pyenv                                                                                                                                                        
export PYENV_ROOT=$HOME/.pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init -)"

mac

bashrc


#pyenv                                                                                                                                                        
eval "$(pyenv init -)"

Verification

pyenv versions

Install anaconda or miniconda

mac linux

pyenv install miniconda3-3.10.1
pyenv global miniconda3-3.10.1

win Download what you like https://www.continuum.io/downloads

Through conda

bashrc


export PATH="$PYENV_ROOT/versions/miniconda3-3.10.1/bin:$PATH"

Create a python environment with conda

conda create -n py35 python=3.5
conda create -n py37 python=3.7

Verification

conda info --e

Use an environment named py35

mac linux

source activate py35

win

activate py35

You can use the environment when (py35) is prompted. Sometimes (py35) appears, but I haven't put it in the environment. If you think the movement is strange, deactivate it once to exit the environment and enter again. If it is still strange, uninstall pyenv and re-enter the environment.

windows should try using conda once

I couldn't enter with pip, but I entered with conda.

conda install -c conda-forge keras
#3.1.0 series
conda install -c menpo opencv3=3.1.0 -n [Environment name]
#3.2.0 series
#3 at the time of writing.1.MSER for 0 series_There seems to be a bug in create, 3.2.I wrote that it was fixed at 0, so I wanted to put it back in. But I didn't enter.
#conda install -c conda-forge opencv=3.2.0
conda install -c conda-forge dlib=19.4
conda install scikit-image
conda install -c conda-forge ffmpeg

2018/6/15: 3.2.0 cannot be used Problem onset

The build is troublesome. The C ++ environment I created is likely to break. ..

And it doesn't disappear. opencv3 doesn't disappear from conda.

conda list | grep open
opencv3                   3.1.0                    py35_0    menpo
sudo conda install -c conda-forge opencv -n [environment]
sudo conda uninstall -c menpo opencv -n [environment]
sudo conda uninstall -c menpo opencv3
I don't know.

Switch the environment.

conda uninstall -c conda-forge opencv=3.2.0
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'cv2'

I don't know anymore. Let's leave it for a while.

https://stackoverflow.com/questions/42310099/failed-to-run-conda-install-c-menpo-opencv3-3-2-0-in-windows7/42535587?noredirect=1

opencv

It's hard to build. Enter with pip or conda.

pip install -U opencv-python

Notes on jupyter

Be sure to use -n to name the environment when conda create. If you install without -n, it will be strange.

ImportError: No module named cv2 or ImportError: No module named tensorflow If something goes wrong, let's recreate the environment.

Shortest memo for kernel switching with jupyter

conda create -n py36 python=3.6
source activate py36
conda install -n py36 jupyter opencv
conda install notebook ipykernel
ipython kernel install --user --name py36 --display-name py36
jupyter noteobok

See here.

Solution when kernel switching on Jupyter does not work

Coexistence of python2 and python3 in jupyter

Look here and set https://qiita.com/utahkaA/items/ae14623ae81f85bea4f5

If you put both miniconda2 and miniconda3 in pyenv, it's OK. Even if I switched from miniconda3 to python2, it was not displayed in jupyter.

When a jupyter kernel error or an unreliable error occurs.

It's a good idea to generate a pass and put the encrypted one in the config file.

...
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 99] Cannot assign requested address

The permissions error is not fixed by pip.

https://stackoverflow.com/questions/27870003/pip-install-please-check-the-permissions-and-owner-of-that-directory A phenomenon that is rarely seen. There are times when it is useless to delete everything under .pyenv and reinsert it.

Like putting owner authority in such an atmosphere
$ sudo chown -R USERNAME /Users/USERNAME/Library/Logs/pip
$ sudo chown -R USERNAME /Users/USERNAME/Library/Caches/pip
--Like putting a user
pip install --user <package name>

I want to run jupyter remotely from the server

Make settings here https://qiita.com/Miggy/items/5466a2c1e968602f3ebe

Output ~ / .jupyter / jupyter_notebook_config.py Set the password to sha1 with ipython, write the contents to jupyter_notebook_config.py or set a little.

After that, it should work if you open the port in each cloud.

For gcp https://towardsdatascience.com/running-jupyter-notebook-in-google-cloud-platform-in-15-min-61e16da34d52

Find out the Python import library path

Opencv Note where you are calling from.

import cv2
cv2.__file__
import imp
imp.find_module('cv2')

In my case, I went to see below .pyenv, which was as expected.

reference

https://github.com/jupyter/notebook/issues/2213 http://jupyter-notebook.readthedocs.io/en/latest/security.html https://qiita.com/SaitoTsutomu/items/aee41edf1a990cad5be6

Recommended Posts

The shortest memo for building a python environment that takes less than 5 minutes to work.
Memo for building a machine learning environment using Python
[Python] Building a virtual python environment for the pyramid tutorial (summary)
From building a Python environment for inexperienced people to Hello world
[Mac] Building a virtual environment for Python
Building a Python development environment for AI development
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
A memo that allows you to change Pineapple's Python environment with pyenv
A memo for creating a python environment by a beginner
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Write about building a Python environment for writing Qiita Qiita
Building a Docker working environment for R and Python
Procedure for building a CDK environment on Windows (Python)
A memo that I touched the Datastore with python
Building a Python environment for programming beginners (Mac OS)
python memo (for myself): About the development environment virtualenv
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
Building a python environment for artificial intelligence (Chainer / TensorFlow / CSLAIER)
Building a development environment for Android apps-creating Android apps in Python
Building a Hy environment for Lisper who hasn't touched Python
How to develop in a virtual environment of Python [Memo]
Build a Python environment and transfer data to the server
Building a Python virtual environment
Precautions that must be understood when building a PYTHON environment
Building a Python virtual environment
A modern environment building procedure for those who want to get started with Python right away
Hypothesis / Verification (176) How to make a textbook that is easier than "The easiest textbook for quantum computers"
A story that didn't work when I tried to log in with the Python requests module
Building a Docker working environment for R and Python 2: Japanese support
How about Anaconda for building a machine learning environment in Python?
Building a Windows 7 environment for getting started with machine learning with Python
A story that struggled to handle the Python package of PocketSphinx
[Introduction to Python] How to use the in operator in a for statement?
From installing Ansible to building a Python environment in Vagrant's virtual environment
A script that returns 0, 1 attached to the first Python prime number
[python] A note that started to understand the behavior of matplotlib.pyplot
[Python] A program that rotates the contents of the list to the left
Everything from building a Python environment to running it on Windows
Building a Python environment on Mac
Building a Python environment on Ubuntu
Building a virtual environment with Python 3
A memo when creating an environment that can be debugged with Lambda @ Edge for the time being
If Python is less than 3.3, use the -R option or the environment variable PYTHONHASHSEED = "random" for DoS countermeasures.
Things to watch out for when creating a Python environment on a Mac
[Introduction to Udemy Python3 + Application] 47. Process the dictionary with a for statement
Work memo to migrate and update Python 2 series scripts on the cloud to 3 series
Try to set up a Vim test environment quite seriously (for Python)
Switch the module to be loaded for each execution environment in Python
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
Let's create a virtual environment for Python
Building a Python 3.6 environment with Windows + PowerShell
I want to build a Python environment
Prepare a development environment that is portable and easy to duplicate without polluting the environment with Python embeddable (Windows)
Building a conda environment for ROS users
Add a Python virtual environment to VSCode
[Python] A program that rounds the score
A memo for making a figure that can be posted to a journal with matplotlib
Use something other than a <br> string for the <br> dict key in Python
A solution to the problem that the Python version in Conda cannot be changed
I want to create a nice Python development environment for my new Mac