HomeBrew Mac change Python Path - macos

I am trying to install PyQT and I used PyQT. Is has been installed using home brew. But When I try to import it, python can't. I get the following warning in Home brew. I am new to Mac and can't figure out how to change the python path. Any help would be great.
For non-homebrew python (2.x), you need to amend your PYTHONPATH like so:
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

You should edit ~/.bash_profile (create the file if it does not exist) to set the PYTHONPATH environment variable:
export PYTHONPATH=`brew --prefix`/lib/python2.7/site-packages:$PYTHONPATH

Since you installed PyQt by using Homebrew, you should also use Homebrew Python 2.
To install it, run: brew install python
Now, you can import PyQt normally.

Related

Could not load dynamic library 'libcudart.so.11.0' in conda enviroment

I use the conda comment to install tensorflow:
conda create -n tf2.6 python=3.9
conda install tensorflow-gpu=2.6
The log tells me it was succesuflly installed.Then in python when I import tensorflow, it shows Could not load dynamic library 'libcudart.so.11.0'. From the log, I found it installed cudatoolkit and cudnn when installing tensorflow. In the directory ./tf2.6/lib, there exist libcudart.so and libcudart.so.11.0. why python cannot recognize it? Some one can give some suggestions. Thank you very much.
In my conda env, there was another version tf2.5. It can work perfectly but I forgot how to installed it since it is a long time when I installed it.
I have the exact same problem, I have found a temporary solution as of now,
doing export LD_LIBRARY_PATH="$CONDA_PREFIX/lib" after activation will include libcudart.so.11.0
If you want to automate it,
add this to env-prefix/etc/conda/activate.d/env_vars.sh
#!/bin/sh
export LD_LIBRARY_PATH="$CONDA_PREFIX/lib"
This will run the script on conda activate and set LD_LIBRARY_PATH

Why anaconda3 install python 2.7

I downloaded and installed Anaconda3-2019.03-MacOSX-x86_64.pkg which should normally install python 3.7. But oddly this is not the case :
(base) iMac-de-Bibi:~ ac$ which python
/Users/ac/anaconda3/bin/python
(base) iMac-de-Bibi:~ ac$ /Users/ac/anaconda3/bin/python --version
Python 2.7.16 :: Anaconda, Inc
Any help would be appreciated
Note : it's my first anaconda installation on this machine
You might have mistakenly downloaded and installed the wrong Anaconda distribution.
You might have changed the Python version in the base environment after the initial installation, by doing something like this:
conda activate base
conda install python=2.7
Update: As reported in a comment, installing pyside downgrades Python.
Have you correctly activated the base environment, and not messed with PATH or PYTHONPATH? I'm not sure about it, but python might be a script that calls the actual Python interpreter. It could pick the wrong one if search paths are off.
In general, I recommend to install Miniconda and create custom environments. Then you can choose whichever Python version you want for each environment, and don't care which one is in the base environment.

"conda export" can not export packages that is installed through pip

I want to use package untangle, unfortunately, it can not be installed through conda, I have to install it using pip. And when I use conda export to export the requirement file, I find that the requirement file doesn't include untangle, is there any way to also include it in conda requirement file and export the conda virtual enviroment ? Thanks
Try this:
/Users/Deepak/anaconda/bin/pip install untangle
Just change "Deepak" to whatever your user folder name is. The anaconda bin folder is the recommended folder in which you should actually store your pip installations within the Anaconda environment.
Open or restart your Jupyter kernel. Try a simple import like this:
import untangle
print("Imported Untangle successfully!")
It worked for me, should work for you too.

How to definitely install virtualenvwrapper with Python3.5 on Mac OS Sierra?

Well, looking around here there are tons of questions about how to correctly installing virtualenvwrapper on Mac. I really tried all of them but for no avail. I've noticed the previous questions don't have the configuration like my computer, so here it is:
Mac OS Sierra 10.12
Python3.5.2 installed from python.org installer for Mac OS
This installation puts Python3.5.2 in this path: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3
I've run python3 get-pip.pycommand to install pip correctly, as I think
sudo pip3 virtualenvwrapper to be sure all settings will be done as they should
As the documentation says, edited ~/.bash_profile with the code below:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/projects
source /usr/local/bin/virtualenvwrapper.sh
Then, whenever I open a new fresh Terminal, I got this:
/usr/bin/python: No module named virtualenvwrapper virtualenvwrapper.sh:
There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly.
I've tried the fixes from others questions, to no avail:
set VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 on virtualenvwrapper.sh
set VIRTUALENVWRAPPER_PYTHON="$(command \which python3)" on virtualenvwrapper.sh
ln -fs /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 /usr/local/bin/python3
alias python=/usr/local/bin/python3
Well, looking forward to anyone with a configuration like mine to see what I'm doing wrong.
This is pretty old, but posting this because I came here from google and finally figured out the right paths.
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
export PROJECT_HOME=$HOME/Devel
source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh
You have to make sure to have the actual python executable. This can be found by just simply browsing in Finder through to /bin and seeing what is there.
Well, after a lot of effort, I've decided to install pip and virtualenvwrapper on Python 2.7 shipped in macOS Sierra.
After that, I wrote the lines below on .bash_profile. Maybe there's something redundant here but, it works.
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Documents/Projects/
ln -fs /Users/myusername/Library/Python/2.7/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh
ln -fs /Users/myusername/Library/Python/2.7/bin/virtualenv /usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
After that, I've installed Python 3.5.2 from python.org and created a new enviroment pointing to it and everything is working just fine.
mkvirtualenv --python=python3.5 env_name

Where is PyGTK for Mac OS X?

Is there a binary out there for the current mac os x, python for PyGTK? I work with multiple desktop environments (mac, windows, gnome) and really consider python's lack of cross platform GUI's a problem. Does anyone know where I can find a built version of PyGTK and GTK for Mac?
I cant clone the git repository, it keeps timing out.
brew install pygtk worked for me (requires homebrew).
Confirmed to work with OS X 10.10 too, but by default it will install it into brew's Python distribution, so if you are still using the native python, it will not find it.
I don't use macports but it seems that jhbuild works for me. Below is the steps that I've done.
download gtk-osx-build-setup.sh from: https://raw.github.com/jralls/gtk-osx-build/master/gtk-osx-build-setup.sh and save it to your home directory.
fire up terminal and navigate to your home directory and run the command sh gtk-osx-build-setup.sh
the shell script will warn you that ~/.local/bin isn't added to your environment variable to do this, edit your .profile file located at your home directory and /Users/<username>/.local/bin to your environment variable. to know more on how to edit this file check out: http://www.tech-recipes.com/rx/2621/os_x_change_path_environment_variable/
after that, do a ~/.local/bin/jhbuild bootstrap command. it will download and install some necessary utilities.
download and install the beta version of the gtk+ osx framework at: http://ftp.imendio.com/pub/imendio/gtk-osx/Gtk-Framework-2.14-LATEST.dmg
before installing the meta-gtk-osx-python, you need to build and install some other packages that jhbuild doesn't install automatically, so what i did was i installed libpng by doing the command: ~/.local/bin/jhbuild build libpng
you also need to install libtiff so do the command: ~/.local/bin/jhbuild build libtiff
and also gtk-doc is needed so: ~/.local/bin/jhbuild build gtk-doc
and finally you can now install meta-gtk-osx-python by doing a: ~/.local/bin/jhbuild build meta-gtk-osx-python
Let me know if it works.
There is an installer for PyGTK 2.24 in test here, announced on the PyGTK list.
UPDATE project has moved on macpkg's sourceforge page.
I couldn't make it work with meld (segmentation fault), but sample PyGTK programs work OK.
UPDATE 2 since then a new package Py3GTK3 appeared on the same sourceforge page. Haven't tested though.
There is now a mac package on sourceforge
Download the latest package from http://sourceforge.net/projects/macpkg/files/PyGTK/ and install.
If you're just trying to use the system python, this is all you'll have to do.
If you're not, the following is how to install it with pyenv, which can be installed with Homebrew. With brew installed, you can install version pyenv and Python 2.7.8 with:
brew install pyenv && pyenv install 2.7.8
After you've done that, you'll then have copy the gtk package and its dependencies into your python installation:
cd /opt/gtk/lib/python2.7/site-packages/ && \
cp * ~/.pyenv/versions/2.7.8/lib/python2.7/site-packages/
That's it. You can also similarly install the Py3GTK3 package which has packages for python 2.7 and 3.2 from http://sourceforge.net/projects/macpkg/files/Py3GTK3/.
Have you tried doing it using macports? This website shows how.

Resources