virtualenv's python can't find PyQt4 - python

Running OSX (10.8.2) here, replaced their python with Homebrew's. All good:
$ which python
/usr/local/bin/python
Installed pip, virtualenv with brew python. Installed pyqt with brew.
If I
$ python
>>> import PyQt4
, no problems. However, if I
(env)$ python
>>> import PyQt4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
Why can't the virtualenv python environment see my system-wide install of pyqt?
Thanks!

Related

Trying to resolve ModuleNotFoundError: No module named

Trying to install third party modules on my mac using pip and I am getting this error (Using IDLE as the Python shell):
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
(Have tried multiple modules and all return the same error)
I have installed the modules using:
pip3 install pyperclip
I can see that it has installed into the directory:
/opt/homebrew/lib/python3.9/site-packages
Ive tried going through several of the posts posted on StackOverflow such as this and this but after trying their steps I cant seem to resolve it.
which -a pip3 gives:
/opt/homebrew/bin/pip3
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
/usr/local/bin/pip3
/usr/bin/pip3
which -a python3 gives:
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
/usr/local/bin/python3
/usr/bin/python3
print(sys.version) gives:
3.9.1 (v3.9.1:1e5d33e9b9, Dec 7 2020, 12:44:01)
[Clang 12.0.0 (clang-1200.0.32.27)]
pip --version gives:
pip 22.1.2 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
Running /usr/local/bin/python3 test1.py:
Traceback (most recent call last):
File "/Users/dxz/Downloads/test1.py", line 1, in <module>
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
Thanks
You can run this command for seeing pip3 uses which python:
pip3 --version
But i guess you are not choosing right python to run your .py file
if you run your .py like this:
python3 main.py
You must be sure pip3 installing libraries to 'python3' linked python or you can run your main.py file with one of pip3 linked python
I mean if pip3 --version gives you
/usr/bin/python3
this python path you can run your main.py like this
/usr/bin/python3 main.py
but if you want to use best practice i recommend to you using virtualenv

QtWebEngineWidgets in virtualenv: ImportError: libQt5QmlModels.so.5: cannot open shared object file: No such file or directory

I'm working on a computer with CentOS 8. To execute a python module, I've created a virtual environment with python3.9 -m venv venv and activated it with source venv/bin/activate. After installing the dependencies with pip 21.3.1, I'm getting the following error when I try to import QtWebEngineWidgets.
(venv) [user#localhost myprog]$ python3 -c "from PyQt5 import QtWebEngineWidgets"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: libQt5QmlModels.so.5: cannot open shared object file: No such file or directory
However, when I look in the site-packages directory of the virtual environment, the file exists.
(venv) [user#localhost myprog]$ find venv/lib64/python3.9/site-packages/* -name "libQt5QmlModels*"
venv/lib64/python3.9/site-packages/PyQt5/Qt5/lib/libQt5QmlModels.so.5
venv/lib64/python3.9/site-packages/qt5_applications/Qt/lib/libQt5QmlModels.so.5
The output using `QT_DEBUG_PLUGINS=1" is the same as without:
(venv) [user#localhost myprog]$ QT_DEBUG_PLUGINS=1 python3 -c "from PyQt5 import QtWebEngineWidgets"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: libQt5QmlModels.so.5: cannot open shared object file: No such file or directory
Further details:
If I install the modules PyQt5, PyQt5-sip and QtWebEngineWidgets outside of the virtual environment, the import works without problems (outside of the venv).
Using other python versions for the virtual environment (tested: 3.6, 3.8) the problem doesn't appear either
What am I doing wrong? Why can't the libQt5QmlModels.so.5 be found?
I've read a question with the same title but it didn't help, since I've already installed/upgraded the modules listed in the solution.

packages not available when importing in sudo python3

So I am using pip through conda to install packages for python3. One package in particular, called keyboard i am running into issues with.
Specifically, If I write:
>import keyboard
>keyboard.wait('s')
I run into: ImportError: You must be root to use this library on linux.
However, if i try to run it with admin privelages opening python3 with: sudo python3 I run into the problem:
> import keyboard
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'keyboard'
Somehow the package is not recognised anymore. what is happening?

How to install missing wx module on Python 2.5?

I have developped a tool under python 2.5 and can't upgrade to a newer python version as I need to use an API developped under python 2.5 as well.
I recently tried my tool under another machine and it seems it hasn't wx module installed as you can see below:
>>> import wx
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named wx
So I searched for the wxpython source. However once I tried to install the source with:
D:\tmp\wxPython-4.0.0b2>c:\Python25\python.exe setup.py install
I got following error:
Traceback (most recent call last): File "setup.py", line 15, in
from setuptools import setup, find_packages ImportError: No module named setuptools
I can't either install whl files as I don't have pip.
So, how can I install wxpython for python 2.5 under Windows?
Is there any executable there in the web that I couldn't find? May there be a workaround by copying the wx module from a python directory from another computer?
As I had to install wxpython 2.7.2.0 I finally got it from wxPython2.7-win32-ansi-2.7.2.0-py25.exe.
As stated in Patrick's comment all wxpython executables for any version are under https://sourceforge.net/projects/wxpython/files/wxPython/

Mac reinstall Python

I tried to use the Coursera course downloader from here and it worked for few courses but not all. They have recommended to use Python3.X. So I uninstalled Anaconda (version 2) from my Mac and installed Python3.5.1 from Python's website but still the course downloaders did not work as it was using default Python 2.7.
So I deleted Python from /usr/local/lib and now nothing is working. When I do which python it shows ``usr/local/bin/pythonand bothpythonandpython3` runs.
But when I do pip install coursera it throws error as follows:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
And when I do sudo easy_install pip, I get the following error.
Traceback (most recent call last):
File "/usr/local/bin/easy_install", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
try Homebrew http://brew.sh/
brew install python3
curl bootstrap.pypa.io/get-pip.py | python3
Your Mac should have Python 2 and Python 3 installed by default. in the terminal "python" will launch Python2, "python3" will launch Python3. With Anaconda you could have just kept the Python 2 version and created an environment for Python 3, http://conda.pydata.org/docs/using/envs.html#managing-environments.
This is the solution you will most likely need, No module named pkg_resources. Setuptools is causing the issue and you will need to wget ez_setup.py. Reinstalling Anaconda will save you a lot of time and pain.

Categories