I've installed ujson using command pip install ujson
and when I've tried to run my python project it returns
ImportError: No module named ujson
OS version: Red Hat Enterprise Linux Server release 7.2 (Maipo)
Python version: Python 2.7.6
pip list: ujson (1.35)
Any help please?
The problem was that the PYTHONPATH variable is empty, and when I added the path to the variable it works.
export PYTHONPATH=$PYTHONPATH:/usr/lib64/python2.7/site-packages
Related
I'm using Ubuntu 14.04 and recently I have installed Python 3.7 instead the default 2.7
I have also updated the alias to version 3.7, however; when I install new packages that require 3.6 and later, it shows me that python (2.7 detected). Below, I attach an example for the issue showing that installing NetworkX version 2.5 (which requires 3.6 and later python versions) cannot achieved due to the detection of python 2.7
Proof of Python 3.7 is working
mininet#mininet-vm:~$ python
Python 3.7.0 (default, Jun 28 2018, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[7]+ Stopped python3.7
Example of how python 3.7 cannot be detected
mininet#mininet-vm:~$ pip install networkx
Downloading/unpacking networkx
Downloading networkx-2.5.tar.gz (1.5MB): 1.5MB downloaded
Running setup.py (path:/tmp/pip_build_mininet/networkx/setup.py) egg_info for package networkx
NetworkX 2.5+ requires Python 3.6 or later (2.7 detected).
For Python 2.7, please install version 2.2 using:
$ pip install 'networkx==2.2'
Complete output from command python setup.py egg_info:
NetworkX 2.5+ requires Python 3.6 or later (2.7 detected).
For Python 2.7, please install version 2.2 using:
$ pip install 'networkx==2.2'
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_mininet/networkx
Storing debug log for failure in /home/mininet/.pip/pip.log
Any solution/suggestion will be highly appreciated,
When you install another version of python on top of another, the path of the new python and pip are added to the PATH. This can create some collisions.
So when you type pip you call the python 2 pip because this is the first match in your PATH.
But why it works with the interpreter?
Python 2 only has the py keyword to invoke the interpreter, python 3 has both command py and python. Thats why you can bypass the collision.
How to resolve collisions?
If you don't plan to use python 2, you can remove the PATH of the python interpreter and pip for python 2. Or you can use pip3 to invoke pip for python 3.
A better workaround to avoid python collisions and by extend packages collisions, you can check virtual environments.
I have quite a few versions of python installed (running macOS). I installed scrapy with pip install scrapy, and it succeeded. When I use it e.g.
scrapy startproject newProject
I see ModuleNotFoundError: No module named 'six', indicating that I need to install that module (six).
Note: I could easily fix the specific error by installing six for all versions of python installed, but solving that problem isn't what I'm trying to work out here.
Specifically what I'm after here is how to know what version of python a command line utility is using when it runs?
pip install will install package under pythonxxx/site-packages, the concrete location is up to which python version the pip used.
use pip -V to see the pip path and the related Python version. For you question, missing six module, pip install six should be enough, which will install six to the same Python version of scrapy.
After install scrapy, we could also enter scrapy shell, and use the below code to see where scrapy is
scrapy.__file__
To check the version of python from within a script or the REPL you can use the sys module.
For example:
>>> import sys
>>> sys.version
'3.8.5 (default, Jul 21 2020, 10:48:26) \n[Clang 11.0.3 (clang-1103.0.32.62)]'
I just installed a nvidia and cuda driver. After that a python program that was running before now gives the error "No module named '_tkinter'"
I use python 3.5 and "import tkinter" now results in the same error.
"sudo apt-get install python3-tk" results in "python3-tk is already the newest version". So somehow tkinter is available but not seen...
Any idea what I can do? I also have python3.6 installed. Maybe any wrong configuration...?
python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
import site; site.getsitepackages()
['/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist packages', '/usr/lib/python3.5/dist-packages']
which -a python3
/usr/bin/python3
The python3-tk package is a virtual package which refers to the specific 3.x version e.g. python3.5-tk or python3.6-tk.
Since you said you have also installed python 3.6, Do you see the same error message if you try running the application with Python 3.6 ? You may have to change your path to refer to your python 3.6 environment or just use virtualenv before invoking your application.
# You can also try this:
sudo apt install python3.5-tk
I've tried importing boto3 in python3 it's working, but i've tried boto3 in python2.7, it is throwing following error.
python3
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
>>> import boto3
>>> exit()
$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
>>> import boto3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named boto3
How we can make boto3 to work with python2.7 ?
Notice that packages are not shared between python versions. If you install a package in your python3.x local version, it doesn't mean the package will be installed in your python2.x local version...
First of all do the following:
pip freeze
If boto3 package isn't there, great! install it:
pip install boto3
if it is there then verify what pip is being used and make sure to use the pip linking to your python2.x version:
which pip
you can create a symlink to use pip for python2.7... or even better, use pyenv to manage your python versions and virtualenv to isolate your workspace for a given python version.
https://github.com/yyuu/pyenv
https://virtualenv.pypa.io/en/stable/
As answered already pip install boto3 will resolve this error.
I would suggest using one version of Python (either 3 or 2) for your application.
Even if the OS relies on python2, your application can make use of python3.
Anyways, python2 EOL is 2020 - so python2 will slowly diminish.
I've created new virtual env and activated it. It is working good in New virtual env.
virtualenv path/to/my/virtual-env
source path/to/my/virtual-env/bin/activate
Please bear with me as I am completely new to programming/python, etc.
I am attempting to install the pycurl module on my local win32 machine. I do not know anything about compiling, and I have attempted to install the module through an msi installer located here:
http://pycurl.sourceforge.net/download/
and I am using the pycurl-7.19.5.win32-py3.4.msi download, with Python 3.4.
I have downloaded it, and when I attempt to run a python query using the command prompt, I receive the error:
ImportError: No module named 'pycurl'
When I run the script without importing pycurl, it runs fine, so I know I have python installed successfully.
What am I doing wrong? I don't want to resort to compiling as that is going in completely foreign territories for me. I'd like to learn how to install modules into python for future purposes as well.
Try installing pycurl from this site, where all modules are as Windows binaries. Installing it and then trying to import pycurl works fine for me (you have to download appropiate .whl for your Python version & platform, then run):
..\Downloads>pip install pycurl-7.19.5.3-cp35-none-win32.whl
Installing collected packages: pycurl
Successfully installed pycurl-7.19.5.3
..\Downloads>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
>>> import pycurl
>>> pycurl
<module 'pycurl' from 'C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\pycurl.cp35-win32.pyd'>
The problem you describe may happen when you have multiple versions of Python installed without using virtualenv.
Use pip instead:
pip install pycurl
Edit 2020-12-11:
Pycurl no longer builds binaries. The last binaries available are for Python 3.4 or 3.5.
If you're still using Python 3.4/3.5, and you don't want to/can't build from source, you can install the last available official binary builds from pip using:
pip3 install --only-binary :all: pycurl
WARNING: the latest binary build may be behind the latest source version and therefore have security bugs.