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.
Related
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 want to start with I am new to the python language and am learning on my own. My issue is that I am installing the modules that I'm trying to use. The installs are successful but do not exist when I try to import them. I am using Visual Studio Code, Python 3.6, and Anaconda on Windows 10.
I am trying to use pyttsx3, SpeechRecognition and pocketsphinx.
$pip list
This gives me a very large list but does not contain either of my installed modules.
$python -m pip list
Gives me smaller output with them.
Package Version
----------------- ---------
beautifulsoup4 4.6.0
bs4 0.0.1
certifi 2018.4.16
chardet 3.0.4
click 6.7
gTTS 2.0.0
gTTS-token 1.1.1
idna 2.6
pip 10.0.1
pocketsphinx 0.1.3 #Here
pypiwin32 223
pyttsx 1.1
pyttsx3 2.7 #Here
pywin32 223
requests 2.18.4
setuptools 39.1.0
six 1.11.0
SpeechRecognition 3.8.1 #Here
urllib3 1.22
wheel 0.31.0
I know their installed but when I try to use any of the imports.
$python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyttsx3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyttsx3'
I am fine with this being something small on my part due to my lack of knowledge with this language, but I have done a full days worth of research trying to solve this myself.
Edit:
$pip --version
pip 9.0.1 from C:\Users\Keiro\Anaconda3\lib\site-packages (python 3.6)
You have two versions of pip perhaps two different installations of python as well. One with Anaconda and other one by main site.
Stick to one version and if you install in that use that environment in Visual Studio(Or VS Code)
You have installed those in anaconda which the standard installtion of Python wont recognize..
Open Python prompt from Anaconda Navigator >> Choose the environment (Select base for default) >> Open with Terminal [Or Open with Python]
>>python
>>import pyttsx3
In Visual Studio code set the same environment
Ctrl+Shift+P >> Select Python interpreter
Choose the anaconda location.
Volla. Now it should work
I had the same problem and found the answer in an old forum.
Write "pip3" instead of "pip".
So the code is:
pip3 install pyttsx3
(Source: bash: pip: command not found)
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.
I have installed python on my macbook with the python installer from Python.org. Subsequently, I went and installed pip, ipython, and numpy. Everything seemed fine. However, now I am getting the following problem. I can import numpy when I run ipython, but not when I run regular python.
E.g.
Logister-MacBook-Pro:~ Logister$ ipython
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
Type "copyright", "credits" or "license" for more information.
IPython 3.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import site; site.getsitepackages()
Out[2]:
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/Library/Python/2.7/site-packages']
However, when I try to do the same thing in python 2.7.9:
Logister-MacBook-Pro:~ Logister$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> import site; site.getsitepackages()
['/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/site-python',
'/Library/Python/2.7/site-packages']
When I try to install numpy via pip it gives me the following response:
Logister-MacBook-Pro:~ Logister$ sudo -H pip install numpy
Requirement already satisfied (use --upgrade to upgrade):
numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
It seems like python 2.7.6 understands where to find numpy, but 2.7.9 does not. Either, how can I point 2.7.9 to the right place, or how can I install numpy so 2.7.9 sees it as well?
Edit: I can run:
site.addsitedir('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
In 2.7.9 and then I am able to import numpy. But I dont want to do this every time I launch 2.7.9. Is there a permanent fix? Also, how do I get ipython to run 2.7.9 instead of 2.7.6?
I had a similar problem.
There is two differences versions of python installed on your computer.
Then you´ve installed numpy on python 2.7.6. but the folder of python 2.7.9 haven't numpy. Do you understand?
Other thing your macOS have a groups of variables called "Environment Variables" there it's identifying the command python with python 2.7.9.
Then if you want to use numpy with the interpreter of python do you need change the Enviroment Variables for the command "python" take the version 2.7.6 or install numpy at python 2.7.9 and work with both versions.
Good luck!
With 2 different version you must have 2 python interpreters on your machine. They are installed on different locations with different libraries. So its just right that you cannot find the module installed on interpreter A while using the interpreter B. The which command can be useful to you to figure out where those interpreter are. You can make a symbolic link manually from a folder to another but it would mess up your mind, and you probably gonna get lost later.
I recommed you to install python and ipython via Homebrew, so it would automatically do all the hard work for you.
Install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Since you said numpy, you are probably looking for scientific stuff so:
# set up some taps and update brew
brew tap homebrew/science # a lot of cool formulae for scientific tools
brew tap homebrew/python # numpy, scipy, matplotlib, ...
brew update && brew upgrade
# install a brewed python
brew install python
Later you can run, but I recommend you to follow this tutorial:
brew install zmq
pip install ipython[all]
I was able to solve the problem by adding the following line to my .bash_profile:
export PYTHONPATH=${PYTHONPATH}:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
I then changed the Ipython version by following this stackoverflow question.
I'm trying to use pymongo in the IDLE shell on MAC OS X 10.9, but I can only do it in terminal.
when I call import pymongo in IDLE I get the following error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pymongo
ImportError: No module named 'pymongo'
but I use python in terminal I get this:
$ python
Python 2.7.5 (default, Sep 12 2013, 21:33:34)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>>
I can then use it with MongoDB.
Have I made some sort of install error? I'm doing this to learn mongoDB so I'm relatively new to this. Any help is much appreciated.
From the information you supplied in the comments, it appears you have installed a version of Python 3.3.4 on your system but you have installed the PyMongo distribution to an instance of Python 2.7, probably the Apple-supplied system Python 2.7 shipped with OS X 10.9. When you install a third-party package (or "distribution"), it is normally associated only with the Python instance that you used to install it. There are several common ways to install such packages. One way is to use the easy_install command, as is suggested on the PyMongo page. However, the easy_install command is also associated with a particular Python instance. On recent OS X releases, Apple supplies easy_install commands that are associated with and install into the system Pythons. So it's a common pitfall on OS X to install a newer version of Python alongside the system Python but then use the default easy_install command with the result that the package you want ends up installed in the wrong Python version. One solution is to install a separate version of easy_install for each Python version you install. The easy_install command is provided by the setuptools package. However, these days the recommended installer tool for Python is pip which provides more features than easy_install, including the ability to uninstall packages, and is actively supported in the community.
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python3.3 get-pip.py
python3.3 -m pip install pymongo
python3.3 -c "import pymongo; print(pymongo.version)"
-> 2.6.3
You also need to install a version of pip for each Python instance that you use. There are other ways to invoke pip but, by using the way shown above, you know which version of Python you are using and you are less likely to end up with the situation you have now. There are other tools you can use in addition, like virtualenv, but, particularly on OS X, pip should be sufficient to handle most beginning use cases.