CERN ROOT from Miniconda on Mac OS High Sierra: libpng conflict - python

I am trying to install Python 3, CERN ROOT and Jupyter lab from miniconda on my mac (OS High Sierra 10.13.4). I don't want to touch my working system install, which is Python2.7 with CERN ROOT on top so I'm going to make a separate environment.
This is how my $PATH looks like when I start:
/usr/local/Cellar/root/6.10.08/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
From a fresh terminal I do:
wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash Miniconda3-latest-MacOSX-x86_64.sh
This installs miniconda3 into /Users/urania277/miniconda3, and adds the following line to my .bash_profile
export PATH="/Users/urania277/miniconda3/bin:$PATH"
so that when I open a new window my PATH acquires that. (As an aside, this seems to be deprecated in the new version of conda, but it doesn't affect the following).
In a new window, I then open conda, add the appropriate channels:
conda config --add channels https://conda.anaconda.org/NLeSC
and create/install the environment I want:
conda create --name=Root6Python3 root=6 python=3
...
conda activate Root6Python3
After installation, I source the ROOT script to get the environment set up
source /Users/urania277/miniconda3/envs/Root6Python3/bin/thisroot.sh
but when I try to start ROOT I get what I believe is a libpng conflict:
(Root6Python3) jocke:~ urania277$ root
dyld: Symbol not found: __cg_png_create_info_struct
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /Users/urania277/miniconda3/envs/Root6Python3/lib/libPng.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Abort trap: 6
I've seen a number of variants of this error on this website but none of the recipes I have found solved my problem. Any hints?
Thanks!
Caterina

Related

Unable to move the Stable Diffusion pipeline to my M1 MacBook

I am following the steps stated here: How to use Stable Diffusion in Apple Silicon (M1/M2).
At my local MacBook M1 machine, I saved the below script in stable-diffusion.py file:
# make sure you're logged in with `huggingface-cli login`
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe = pipe.to("mps")
# Recommended if your computer has < 64 GB of RAM
pipe.enable_attention_slicing()
prompt = "a photo of an astronaut riding a horse on mars"
# First-time "warmup" pass (see explanation above)
_ = pipe(prompt, num_inference_steps=1)
# Results match those from the CPU device after the warmup pass.
image = pipe(prompt).images[0]
Now when I am trying to execute: python stable-diffusion.py from Terminal, I am getting following error:
Traceback (most recent call last):
File "/Users/apple/Desktop/area_51/stable-diffusion.py", line 2, in <module>
from diffusers import StableDiffusionPipeline
ModuleNotFoundError: No module named 'diffusers'
In order to fix it even I tried: pip install diffusers, however I still got same error.
Am I missing anything over here?
If you have already installed diffusers but are still encountering the ModuleNotFoundError, it's possible that the module is installed in a different Python environment than the one you are running your script from. In that case, you may need to check your Python environment settings and ensure that the module is installed in the correct environment.
To check your Python environment settings, you can use the following steps:
First, determine which Python interpreter you are currently using by running the following command in your terminal:
which python3
This should output the path to the Python interpreter that is currently being used. (I assume you're using python3. If you are using python2 for some ungodly reason, you should switch to python3.)
Next, ensure that the diffusers package is installed in the environment associated with the Python interpreter you are using. You can do this by running the following command:
python3 -m site
This will output information about the Python installation, including the location of the site-packages directory where installed packages are stored.
Look for a line that says "sys.path" or "USER_SITE" to find the location of the site-packages directory. This is the directory where Python looks for installed packages.
Check if the diffusers package is installed in the site-packages directory. You can do this by looking for a directory called diffusers inside the site-packages directory.
For example, if the site-packages directory is located at /usr/local/lib/python3.9/site-packages, you can check for the diffusers package by running the following command:
ls /usr/local/lib/python3.9/site-packages | grep diffusers
If the diffusers package is installed, this command should output a directory called diffusers. If the package is not installed, the command will not output anything.
If the diffusers package is not installed in the correct environment, you can try installing it using the appropriate package manager for that environment. For example, if you are using a conda environment, you can try installing the package using conda (conda install -c conda-forge diffusers). If you are using a virtual environment created with venv, you can try activating the environment and installing the package using pip (pip3 install diffusers).

GDAL in virtual environment vs PostgresSQL 11

I created a virtual python environment and installed the GDAL-Wheel into it:
When I run my python-program I get the following message:
ERROR 1: PROJ: proj_identify: C:\Program Files\PostgreSQL\11\share\contrib\postgis-3.2\proj\proj.db contains DATABASE.LAYOUT.VERSION.MINOR = 0 whereas a number >= 2 is expected. It comes from another PROJ installation.
I have also installed postgresSQL 11 on my machine.
Seems GDAL-Wheel and PostgresSQL 11 interfere /disturb each other?
the GDAL-wheel is from:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
Check the package path under system environment its probably pointing to PostGIS folder. Get the windows binary pyproj file from the site you got the GDAL. Install with pip install, after it's done re run the pip install command to get the directory path.
Now just change the variable path for PROJ_LIB under system environment variables.

Installing gdal with conda and setting environmental variables

I have been trying to get the gdal library work using Python 2.7 and Anaconda in Windows 8 environment.
Besides gdal, I have also installed libgdal (frankly, I don't really understand the difference between the two). I now seem to have gdal 2.1.0 and 2.0.2 as well as libgdal 2.1.0.
However, when I run my Py code, there is a gdal error:
'gdalwarp' is not recognized as an internal or external command,
operable program or batch file.
I have already set the GDAL_DATA environmental variable to point to
C:\Anaconda\pkgs\libgdal-2.1.0-vc9_0\Library\share\gdal
I have also added a path, although I am not entirely sure where this should point to:
C:\Anaconda\pkgs\libgdal-2.1.0-vc9_0\Library\bin
I have tried the same with gdal 2.0.2 without success. gdalwarp.exe does seem to exist under libgdal 2.1.0 and gdal 2.0.2.
Any ideas? Is there an issue with the installation or have I not set the environmental variables correctly?
FYI, I have tried various installation commands, notably:
conda install gdal
conda install -c conda-forge gdal
conda install -c anaconda gdal
Addendum: I have found a manual solution: I set the GDAL_DATA and PATH variables in the terminal (pointing to libgdal 2.1.0) before running the code...
However, there is still an issue when I run my Py code: it is supposed to convert a tiff file to shp with gdal_polygonize:
cmd = 'gdal_polygonize.py %s -f "ESRI Shapefile" %s'%(dst_tif, dst_shp)
There is no error but the shapefile is not created (which leads to an error later on in the code). Any ideas as to why gdal is still not working correctly?
I have tried pointing the env variables to osgeo:
set PATH=%PATH%;C:\Anaconda2\Lib\site-packages\osgeo\scripts
set GDAL_DATA=C:\Anaconda2\Lib\site-packages\osgeo\data\gdal
Gdalinfo works but the gdal_polygonize used in my Py code does not appear to work.
The key is the activation script which is (potentially) executed when activating the environment. Not every GDAL build for Conda contains this. In my experience recent Conda-Forge builds are really good.
With your requirements of py27 and GDAL 2.1 i can get it working by following these steps:
1) Create a new environment: conda create -n gdaltest python=2.7
2) Activate: activate gdaltest
3) Install GDAL: conda install gdal=2.1 -c conda-forge
4) Reactivate environment: deactivate + activate gdaltest
This forces the just installed activation script to be executed, this sets the environment variables.
If i start python and run os.system("gdalinfo"), i can see its picked up correctly. And running os.environ['GDAL_DATA'] confirms the path is set correctly.
You can view the (de)activation script yourself at:
C:\Miniconda3\envs\<env name>\etc\conda\activate.d\gdal-activate.bat
A few years ago this didn't work as well as it does today, so make sure you have a recent Conda version (4.3.x) etc.
The benefit of this method is, that when switching environments, your paths are also changed accordingly. A "hard coded" GDAL_DATA path could potentially cause some compatibility issues if you mix and match different GDAL versions (although normally is should work OK).

Spyder pip install not found: OSX

So I have installed spyder through the pip install spyder command on my terminal.
When I type pip show spyder I receive:
Name: spyder
Version: 3.1.3
Summary: Scientific PYthon Development EnviRonment
Home-page: https://github.com/spyder-ide/spyder
Author: The Spyder Project Contributors
Author-email: UNKNOWN
License: MIT
Location: /Users/g******/anaconda/lib/python3.5/site-packages
Requires: pyzmq, chardet, nbconvert, numpydoc, qtconsole, qtpy, jedi, pickleshare, pep8, pyflakes, pygments, rope-py3k, sphinx, qtawesome, psutil, pylint
Also, when I launch anaconda platform and go to the environments>root I see that spyder is there. But, in the Home section it shows that is not installed.
Furthermore, on terminal, when I type python it runs smoothly, when I do the same for jupyter notebook again it runs smoothly. But, when I type spyder I get:
G****-MacBook-Pro:~ g*****$ spyder
-bash: /Users/g*****/anaconda/bin/spyder: No such file or directory
I think it has to do with the directory the programmes are installed. Nevertheless, it seems weird to a newbie like myself. Any suggestions how to launch spyder?
UPDATE: Ok so when I execute which python on terminal, I get the location:
/Users/g*****/anaconda/bin/python
Now, I am 100% sure that it has to do with the locality of the programme. Eventhough, still seems weird to me that I can see the package on the root environment of Anaconda but I am not able to launch it.
It seems like bash can find the program in $PATH because it's adding the full path (/Users/.../bin/spyder), but you could verify this with which:
$ which spyder
/Users/.../bin/spyder
After that, there might be a problem with that executable, probably in the shebang, the first line that starts with #! that instructs bash on how to run the program.
$ head `which spyder`
#! (there should be a valid path to Python here...)
import blah
...
That path is probably broken, so you'll need to figure out why and fix your environment. If you moved the path it's referring to around or deleted it, that's why. Other than hand-fixing the path, you might be able to uninstall the package and reinstall it; Python will correctly set the shebang on installation.

Conda-build version not installed

C:\Users\%USER%>conda info
Current conda install:
platform : win-32
conda version : 3.16.0
conda-build version : not installed
python version : 2.7.10.final.0
requests version : 2.7.0
root environment : C:\Users\%USER%\Miniconda (writable)
default environment : C:\Users\%USER%\Miniconda
envs directories : C:\Users\%USER%\Miniconda\envs
package cache : C:\Users\%USER%\Miniconda\pkgs
channel URLs : https://repo.continuum.io/pkgs/free/win-32/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/win-32/
https://repo.continuum.io/pkgs/pro/noarch/
config file : None
is foreign system : True
# NOTE:
# root directory 'C:\Users\%USER%\Miniconda' is uninitialized
I see my root directory is not initialized.
Additionally when I try to install a package (pandas eg) I get the following error:
C:\Users\%USER%>conda install pandas
Error: This installation of conda is not initialized. Use 'conda create -n
envname' to create a conda environment and 'source activate envname' to
activate it.
# Note that pip installing conda is not the recommended way for setting up your
# system. The recommended way for setting up a conda system is by installing
# Miniconda, see: http://repo.continuum.io/miniconda/index.html
I assume they are related but I am not sure the course of action.
I had anaconda/python27 up and running but wanted to update matplotlib and thought to reinstall python with conda to be "up to date".
The error is documented here, but to be honest I do not really get it.
I regret this as it is a bit tough to get up and running again!
I had a similar problem, but with Anaconda on Windows 8.1.
The python env variables are set from a previous python install.
The installer did not update (user)PYTHONHOME, (system)PYTHON_DIR, and (system)PYTHONPATH, so I manually set them to /Users/me/Anaconda/.
conda update conda
gave the error mentioned above. I added a new conda environment...
conda create -n notebook jupyter
activate notebook
which succeeded, but...
conda info --envs
...gives...
notebook C:\Users\<me>\Anaconda\envs\notebook
root * C:\Users\<me>\Anaconda
...and...
conda info
...
# NOTE: root directory 'C:\Users\me\Anaconda' is uninitialized.
I suspect that the installer failed due to the presence of the environment variables. I deleted the environment variables and the /Users/me/Anaconda directory, then installed miniconda.
All seems to be well now.
Note:
I had previously installed python at least three different ways.
{Chocolatey, Anaconda(all)[failed], python msi}

Categories