Installing ipython qtconsole mac osx - can't find pyqt on system - python

I have followed the following steps in order to set up a data science environment on my laptop, running osx yosemite 10.10.3.
When I enter the suggested command at the end of the guide "ipython qtconsole" I get an error message which suggests that pyqt is not installed / it does not exist where it is currently looking for it:
" ImportError:
Could not load requested Qt binding. Please ensure that
PyQt4 >= 4.7, PyQt5 or PySide >= 1.0.3 is available,
and only one is imported per session.
Currently-imported Qt library: None
PyQt4 installed: False
PyQt5 installed: False
PySide >= 1.0.3 installed: False
Tried to load: ['pyside', 'pyqt', 'pyqt5']"
I have however installed these formulas using brew:
brew install qt
brew install sip
brew install pyqt
and have confirmed that they now are installed by running the command
brew list
and confirmed that they are in the outputted list. So I should have a version of pyqt installed. After installing pyqt I got the following message output:
==> Caveats
Phonon support is broken.
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> homebrew.pth
which I did.
So I am not sure how to proceed, I need to tell ipython where the location of pyqt is on my system I assume, but not sure how to do this.

I added two more steps and I am happily using the qtconsole.
sudo pip install pyside
pyside_postinstall.py -install
It worked for me on OSX 10.10.
Source: The PySide module docs docs

I was having the same exact problem. This solved it: past export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH in the terminal to link your brewed packages with your OS.

Related

How can I run pyqt5 on my Mac with M1chip (ppc64el architecture)?

Now. When I run it. The error comes
ImportError:
dlopen(/Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so,
2): no suitable image found. Did find:
/Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so:
mach-o, but wrong architecture
/Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so:
mach-o, but wrong architecture
After hours of trial and error, I was finally able to solve this. My successful configuration is:
Open terminal with Rosetta 2 (https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g)
Use non-homebrew python (mine was in /usr/bin/python3) to create virtual environment
/usr/bin/python3 -m venv env
source env/bin/activate
Upgrade pip
pip install --upgrade pip
Install PyQt5
pip install PyQt5
I needed PyQt5 as a dependency for a Python library and this worked for me. See original post here.
brew install pyqt5
echo 'export PATH="/opt/homebrew/opt/qt#5/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/pyqt#5/5.15.4_1/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
What I ended up doing specifically for pyqt5 was:
brew install pyqt#5
I think for versions 4 and 6 this may work as well. When I went simply brew install pyqt that didn't work unfortunately.
note this is M1 Macbook only
One other thing to try as things settle down with M1s is to try pip3 install pyqt5 in a terminal launched in Rosetta mode (left click -> Get Info -> Open in Rosetta)
Edit (Nov 2022)
It seems that if you don't specifically need pyqt5, pyqt6 is now easily installable via pip on M1/M2 Macs.
python -m pip install pyqt6
I was hoping to install pyqt5 on my M1 mac without Rosetta. I was using it as a dependency of another project that I wanted to install in a venv which requires pyqt5 and was not installable via pipx (urh).
Unfortunately, there currently are no compatible wheels (curl --silent "https://pypi.org/pypi/PyQt5/json" | grep -i arm64), and attempting to install on 3.10 fails with AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'
Thankfully, the homebrew installation of pyqt5 is compiled for arm64 and works well.
My steps were:
$ # Install pyqt5 via homebrew
$ brew install pyqt#5
$ # Note that it's installed in python3.9, not 3.10
$ brew cat pyqt#5 | grep 'depends_on.*python'
depends_on "python#3.9"
$ # Make a python3.9 virtualenv with access to the system's site-packages
$ /opt/homebrew/bin/python3.9 -m venv --system-site-packages .venv
$ source .venv/bin/activate
At this point I was able to install urh into the virtualenv, using the arm64-compiled pyqt5 from hombrew, without neededing Rosetta (and without needing to further "pollute" my system site-packages), and it runs as expected (since the question was about running).
Try installing the pyqt under the ARM architecture as below
arch -arm64 brew install pyqt
In my case it's work: arch -x86_64 brew install pyqt
And all required pyqt start from arch -x86_64 or start from rosetta (through emulator).
You can use it from homebrew, this is the only way I found it working on Mac M1.
First:
brew install pyqt#5
Then:
brew --cellar
brew link --overwrite python
Then you must create/add an alias for python and put it in your .zprofile (Located in Users/username folder, if you press Shift+command+.
This must point to your homebrew python installation location.
alias python ='opt/homebrew/bin/python3'
That way it will link python with your homebrew python and you can run python test.py from terminal (Where your python files are located).
No matter how I tried with pip install, it just shown error and did not work.
I wanted to run PyQt5 under virtual environment with Python3.6.
The following procedures worked for me.
My settings are MBA M1 2020, macOS 11.3.1, and
pyenv versions
> system
> * 3.6.15
pip -V
> pip 21.3.1 from /Users/username/.pyenv/versions/3.6.15/lib/python3.6/site-packages/pip (python 3.6)
Then simply run:
pip install pyqt5-sip
pip install pyqt5
on the terminal (default one, not the one with Rosetta 2).
I had to install PyQt5==5.15.6on my MacM1 into an existing virtual environment.
It did not work using all the methods described here.
So, what I did is :
Open the terminal in rosetta mode
Navigate to my project and activate the virtual environment source venv/bin/activate
Install the package : pip install PyQt5==5.15.6
Open a regular terminal into my project and make sure everything was installed as per the requirements.txt : pip install -r requirements.txt
Everything is running smoothly, now.
If anyone is still having the same problem with installation of PyQT5, I would suggest you to rather lock your focus on PySide6. It is 99% similar to PyQT5 and works well with MacBook m1.
I've been digging the Internet for hours hoping to find the solution but it appears that PyQT5 and PyQT5-tools modules are somewhat broken on MacBook M1 when it comes to downloading them.
I was struggling with installing PyQt5 on M1 mac with MacOS 12.6 (Monterey) inside a virtual environment (using python 3.9). The final solution that worked for me was to use conda for creating and activating the virtual environment.
conda create --name venv python=3.9 conda activate venv
And then simply using conda to install PyQt5 as part of the pyqt package.
conda install pyqt
PyQt6 is out now and supports apple silicon:
https://stackoverflow.com/a/75224682/19486832
No conda support, but pip install is working fine:
python -m pip install PyQt6

Python: installing packages on Mac

I tried to install the pyqt5 package für python 3.9 on Mac.
Since it didn't work via pip3 I installed it via Homebrew
% brew install pyqt5
and it seemed to work since the terminal says, if I try
pip3 install pyqt5
the requirements are already satisfied.
Yet, if I start PyCharm to to write and test my program it can't find the libraries etc.
What do I have to do?
I just tried to brew install pyqt5 on my Mac. brew then installed a new Python 3.9 interpreter (this is viewed as a dependency of pyqt5).
I suspect the same has happened on your system: brew has installed a whole new Python interpreter, and now when you type pip3 at the command line, you're finding the version of pip installed by brew, which is telling you that pyqt5 has been installed.
However, each Python installation on your system as its own set of packages. Your new Python interpreter has pyqt5 installed, but your original Python interpreter still doesn't.
I suspect that PyCharm is configured to use your default (original) Python interpreter, which doesn't have pyqt5 installed.
Try executing the following at your command prompt (terminal): which pip3. If you're shown a path /usr/local/Cellar/... then this confirms that when you type pip3 at the command line you're actually referring to the version of pip corresponding to a Python interpreter installed by brew.
OK, so what to do going forward?
Two options:
Work with this new Python installation. Then, you'll need to install all of the packages in your previous version of Python again (e.g. just because you had Numpy installed on your original Python installation doesn't mean you'll have it installed by default for your new Python interpreter). Further, you'll have to configure Pycharm to use this Python installation. I don't know the exact steps for this, but go to the Preferences tab and look for something along the lines of 'Python Interpreter' underneath 'Project Settings'.
Remove the new Python installation, figure out what's up with pip, install your desired package.
I'd go with 2). It can get messy to have multiple different versions of Python on your system, unless they're managed by an environment manager such as conda.
To that end, what went wrong when you first tried to install pyqt5?

PyQt4 install problems on Ubuntu

I have PyQt4 installed and running with Python2.7 on Ubuntu, this works fine. Now I want to use PyQt4 with Python3.
I have been trying for several hours to install PyQt4 with Python3.4.
I installed sip-4.16.4. This worked fine.
I then tried installing PyQt-x11-gpl-4.11.3.
I get a message:
The Qt Designer plugin was disabled because a dynamic Python library could not be found.
I then ran make and had an error that Python.h could not be found. I then created a sym link as per this answer
I then ran make again I got an error:
fatal error abstractaudiooutput.h No such file or directory and compilation was terminated.
I tried a virtual environment and installed pyhton3.4 from scratch. Things progressed much further than previously but then I again got the same error with abstractaudiooutput.h.
One way to get pyQt4 working in Ubuntu:
Install Ubuntu14.04
Install virtualenv and virtualenvwrapper eg virtualenv, virtualenvwrapper
Create a python3 virtualenv
mkvirtualenv testpy3 -p /usr/bin/python3.4
Now you should see (testpy3) at start of command line.
In this shell install sip (I got it working this way but may be better to download latest from riverbankcomputing as per pyQt below)
pip install sip
make
sudo make install
download pyQt from http://www.riverbankcomputing.com/software/pyqt/download
cd to the download folder, unpack the downloaded file. cd into the unpacked folder.
type
python configure-ng.py
make
sudo make install
Now test with
python
>>import PyQt4
This should work without errors.
Now in PyCharm
file->settings->Project:Project Interpreter select the gear icon on topRHS->add local navigate to your testpy3 virtualenv (eg in /home/user/.virtualenvs). Through PyQt4 doesn't appear in the package list, PyCharm detected it and PyQt4 gui's are working for me.

How to install Pyside for Python 2.7?

Hey I am pretty new to Pyside and am not sure how to download it or Qt? I have a 64-bit Windows computer and am wondering what I need to download once I have downloaded Qt because there is a checklist for like Qt 5.3, Qt 5.2.1, etc. and I am not sure which to download because under those there are multiple options under them like MSCV2012 64-bit and mscv64-bit OpenGL. Basically I am just very lost on what I need and can't seem to find the answer. Could someone enlighten me?
Thanks!
Install pip:
Download pip installer from here and save it in a directory other than C.
If you haven't set your python path: follow this.
Open Command Prompt and cd to that directory where you saved the pip installer.
run: python get-pip.py
Install pyside:
Close and Reopen Command Prompt.
run: cd C:\Python27\Scripts
run: pip install -U PySide
PySide does not yet support the Qt 5.x branch.
Simply running pip install pyside will install bindings that support the Qt 4.8 branch. Thus, you need that version of Qt.
All the steps are mentioned in here, but for your convenience, here goes it inline:
Installing prerequisites
Install latest pip distribution: download get-pip.py [bootstrap.pypa.io] and run it using the python interpreter.
Installing PySide on a Windows System
To install PySide on Windows you can choose from the following options:
Use pip [pypi.python.org] to install the wheel binary packages by issuing the command:
pip install -U PySide
Use setuptools [pypi.python.org] to install the egg binary packages by issuing the command (deprecated):
easy_install -U PySide
Download and install the packages from the PyPI page [pypi.python.org]
Provided binaries are without any other external dependencies. All required Qt libraries, development tools and examples are included.
Then, you can grab the Qt 4.8.6 version from here:
http://qt-project.org/downloads
Please note that there is no installer for VS2012 off-hand, so you should use an older version or mingw. Alternatively, you could also build Qt 4 yourself.

How to install PyQt4 on Windows using pip?

I'm using Python 3.4 on Windows. When I run a script, it complains
ImportError: No Module named 'PyQt4'
So I tried to install it, but pip install PyQt4 gives
Could not find any downloads that satisfy the requirement PyQt4
although it does show up when I run pip search PyQt4. I tried to pip install python-qt, which installed successfully but that didn't solve the problem.
What am I doing wrong?
Here are Windows wheel packages built by Chris Golke - Python Windows Binary packages - PyQt
In the filenames cp27 means C-python version 2.7, cp35 means python 3.5, etc.
Since Qt is a more complicated system with a compiled C++ codebase underlying the python interface it provides you, it can be more complex to build than just a pure python code package, which means it can be hard to install it from source.
Make sure you grab the correct Windows wheel file (python version, 32/64 bit), and then use pip to install it - e.g:
C:\path\where\wheel\is\> pip install PyQt4-4.11.4-cp35-none-win_amd64.whl
Should properly install if you are running an x64 build of Python 3.5.
QT no longer supports PyQt4, but you can install PyQt5 with pip:
pip install PyQt5
You can't use pip. You have to download from the Riverbank website and run the installer for your version of python. If there is no install for your version, you will have to install Python for one of the available installers, or build from source (which is rather involved). Other answers and comments have the links.
If you install PyQt4 on Windows, files wind up here by default:
C:\Python27\Lib\site-packages\PyQt4*.*
but it also leaves a file here:
C:\Python27\Lib\site-packages\sip.pyd
If you copy the both the sip.pyd and PyQt4 folder into your virtualenv things will work fine.
For example:
mkdir c:\code
cd c:\code
virtualenv BACKUP
cd c:\code\BACKUP\scripts
activate
Then with windows explorer copy from C:\Python27\Lib\site-packages the file (sip.pyd) and folder (PyQt4) mentioned above to C:\code\BACKUP\Lib\site-packages\
Then back at CLI:
cd ..
(c:\code\BACKUP)
python backup.py
The problem with trying to launch a script which calls PyQt4 from within virtualenv is that the virtualenv does not have PyQt4 installed and it doesn't know how to reference the default installation described above. But follow these steps to copy PyQt4 into your virtualenv and things should work great.
Earlier PyQt .exe installers were available directly from the website download page. Now with the release of PyQt4.12 , installers have been deprecated. You can make the libraries work somehow by compiling them but that would mean going to great lengths of trouble.
Otherwise you can use the previous distributions to solve your purpose. The .exe windows installers can be downloaded from :
https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/
It looks like you may have to do a bit of manual installation for PyQt4.
http://pyqt.sourceforge.net/Docs/PyQt4/installation.html
This might help a bit more, it's a bit more in a tutorial/set-by-step format:
http://movingthelamppost.com/blog/html/2013/07/12/installing_pyqt____because_it_s_too_good_for_pip_or_easy_install_.html
With current latest python 3.6.5
pip3 install PyQt5
works fine
For Windows:
download the appropriate version of the PyQt4 from here:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4
and install it using pip (example for Python3.6 - 64bit)
pip install PyQt4‑4.11.4‑cp36‑cp36m‑win_amd64.whl
Try this for PyQt5:
pip install PyQt5
Use the operating system on this link for PyQt4.
Or download the supported wheel for your platform on this link.
Else use this link for the windows executable installer.
Hopefully this helps you to install either PyQt4 or PyQt5.
install PyQt5 for Windows 10 and python 3.5+.
pip install PyQt5
If you have error while installing PyQt4.
Error: PyQt4-4.11.4-cp27-cp27m-win_amd64.whl is not a supported wheel on this
platform.
My system type is 64 bit, But to solve this error I have installed PyQt4 of 32 bit windows system, i.e PyQt4-4.11.4-cp27-cp27m-win32.whl - click here to see more versions.
Kindly select appropriate version of PyQt4 according to your installed python version.
You can also use this command to install PyQt5.
pip3 install PyQt5
I am using PyCharm, and was able to install PyQt5.
PyQt4, as well as PyQt4Enhanced and windows_whl both failed to install, I'm guessing that's because Qt4 is no longer supported.
Try using python 3.6,
then install sip
pip install sip
then follow the steps mentioned by #Jay https://stackoverflow.com/a/48078369/8352081

Categories