library referring to wrong version of Python - python

I have multiple pythons installed in my machine, 2.7, 3.5, 3.6, etc and I installed the library called spacy.
And it seems like this library keeps referring to the old version of python which is 3.5. at /usr/local/lib/python3.5/dist-packages.
Python 3.6.5 (default, Mar 29 2018, 03:28:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import spacy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/spacy/__init__.py", line 4, in <module>
from . import util
File "/usr/local/lib/python3.5/dist-packages/spacy/util.py", line 4, in <module>
import ujson
ModuleNotFoundError: No module named 'ujson'
Regardless of this specific library 'spacy', I'd like to know
what is the best way to make library to point to upgraded python which is 3.6, not 3.5. Which path variable should I update?
Please help... I've been wasting too much time on this issue.

Try to install spacy lib by running pip with required python version in module mode:
python3.6 -m pip install spacy

Related

'_ctypes' module missing when python is installed via pyenv

I am trying to set up an environment using pyenv and homebrew on Ubuntu 20.04. There are no problems with my system install of python. However, when I install a specific version of python using pyenv I run into the following problem upon running Jupyter:
> jupyter notebook
Traceback (most recent call last):
File "/home/parzydlo/.pyenv/versions/3.10.3/bin/jupyter-notebook", line 5, in <module>
from notebook.notebookapp import main
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/notebookapp.py", line 76, in <module>
from .base.handlers import Template404, RedirectWithParams
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/base/handlers.py", line 35, in <module>
from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape, urldecode_unix_socket_path
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/utils.py", line 8, in <module>
import ctypes
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
To verify the package is missing:
> python3
Python 3.10.3 (main, Apr 7 2022, 19:51:28) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
When I switch back to system python:
> pyenv local system
> python3
Python 3.9.12 (main, Mar 23 2022, 21:36:19)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>>
Following numerous threads here on SO I installed libffi-dev and tried reinstalling pyenv python but the problem persists. Perhaps it is worth mentioning that I'm using homebrew as my package manager, but had to install libffi-dev using apt.
Finally, I read [this post on dev.to][1] which suggested the following fix:
CC="$(brew --prefix gcc)/bin/gcc-11" \
pyenv install --verbose 3.10.0
Unfortunately, this too did not resolve the issue.
[1]: https://dev.to/ajkerrigan/homebrew-pyenv-ctypes-oh-my-3d9#isolating-the-useful-change
I have similar issue, the trick is you need to reinstall the same python version, e.g pyenv install -f after all apt install lib**-dev.

Unable to import xgboost in Python

I have installed xgboost successfully using pip for Python 2.7.16 (I installed this Python version using Homebrew on macOS High Sierra). My problem is that I'm unable to import xgboost in Python, as per the error message below:
mac-128644:~ user$ python
Python 2.7.16 (default, Apr 12 2019, 15:32:52)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xgboost
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/xgboost/__init__.py", line 11, in <module>
from .core import DMatrix, Booster
File "/usr/local/lib/python2.7/site-packages/xgboost/core.py", line 163, in <module>
_LIB = _load_lib()
File "/usr/local/lib/python2.7/site-packages/xgboost/core.py", line 154, in _load_lib
'Error message(s): {}\n'.format(os_error_list))
xgboost.core.XGBoostError: XGBoost Library (libxgboost.dylib) could not be loaded.
Likely causes:
* OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libgomp.so for UNIX-like OSes)
* You are running 32-bit Python on a 64-bit OS
Error message(s): ['dlopen(/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/8/libgomp.1.dylib\n Referenced from: /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib\n Reason: no suitable image found. Did find:\n\t/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib/libgomp.1.dylib: stat() failed with errno=20']
I've made sure that both my Python version and OS are 64-bit, so the problem is definitely not the second "likely cause." I'm also pretty sure I have OpenMP installed: looking up instructions, for my case I would do brew install llvm and the install was successful. I'm also not sure why it can't seem to find /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib, as I can cd into that directory and see libxgboost.dylib just fine. It looks like later on in the message it did find it, but still throws an error? What exactly is going on here, and what can I do to fix this error?
Install xgboost first:
pip install xgboost
Then use:
brew install libomp
At last:
import xgboost as

PyQt5: ImportError: No module named sip

This has me completely bamboozled. I wanted to compile PyQt5. To do that I first need to compile and install sip. So I compiled and installed sip. Then I compiled and installed PyQt5. No problems so far. Then I tried it out.
$ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sip
>>> import PyQt5
>>> from PyQt5 import QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sip
>>>
What??? I had to have sip installed to compile PyQt5. I had to have sip installed to import it. Why is it now telling me that there is "No module named sip?"
I had this problem with system packages (installed via apt), with a virtual env created with --system-site-packages, and I don't have it inside a proper virtual env. Python3.6, LinuxMint 19.
I had this problem when I was inside (venv) running the python from the venv/bin
it cleared and found sip when I used usr/bin/python
(in my setup they were the same versions, please check you product and setup that the virtual py is not needed)

Why is python3 not finding a module?

Running my script (which imports ply) with python 2.7 works without issue. But trying to run the same script with python3 causes the following. (Note: I'm on v3.10 of ply - the latest which should be compatible with python3).
bos-mpqpu:config_parse rabdelaz$ python3 lexparse.py
Traceback (most recent call last):
File "lexparse.py", line 1, in <module>
import ply.lex as lex
ModuleNotFoundError: No module named 'ply'
bos-mpqpu:config_parse rabdelaz$ pip show ply | grep Version
Version: 3.10
I've installed python3:
bos-mpqpu:config_parse rabdelaz$ python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ply
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ply'
>>>
Try this command if you have pip3
pip3 install ply
This works too:
python3 -m pip install ply
You must install this module for python3.
Python modules, libraries are different for python 2 and 3.
for linux installation:
python 2.7.x : sudo apt-get install python-ply
python 3.x : sudo apt-get install python3-ply
https://www.howtoinstall.co/en/ubuntu/utopic/python-ply
I was facing the same issue but couldn't exactly know what was the problem so I again installed ply library and went to its location and made my project there. Library worked well there.
Install ply library
pip3 install ply
this would show you where the library is stored after successful installation.
Go to the location and make your project their.
This worked for me. Hopefully it would help you too.

"No module named tensorflow" error after installation

After installing the TensorFlow CPU version with virtualenv (in Ubuntu 14.0), when I try to test the installation with Python (not from the source directory), I get the following error:
No module named tensorflow
Any explanation?
I am following the exact sequence of steps from the TensorFlow installation page.
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow
>>>
Tensoflow works only with Python 3.5.x version
Tensorflow does work with python 2.7 https://www.tensorflow.org/install/pip. Just wanted to add it here so no one get it wrong. Cant comment since I don't have the reputation yet :(
Check your env and pip to make sure you have installed it for the correct python version in the env.

Categories

Resources