Issue with Python Path. "ImportError: No module named setuptools" - python

I recently updated to Python 2.7 in order to start working with Django "Django requires Python, specifically Python 2.6.5 - 2.7.x."
As a result I needed to install some of the tools I have been using when I went through the excellent LPTHW Exercise 46
pip from http://pypi.python.org/pypi/pip
distribute from http://pypi.python.org/pypi/distribute
nose from http://pypi.python.org/pypi/nose/
virtualenv from http://pypi.python.org/pypi/virtualenv
Should be easy enough, I had done it all before...
When I run python in terminal I get the below. Note: Python 2.7.5
$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
When I type "which python" I get
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
However when I try to install distribute, nose or virtualenv I get the below error. Note Python/2.6
$ sudo pip install distribute
Exception:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/pip-1.3.1-py2.6.egg/pip/basecommand.py", line 139, in main
status = self.run(options, args)
File "/Library/Python/2.6/site-packages/pip-1.3.1-py2.6.egg/pip/commands/install.py", line 258, in run
import setuptools
ImportError: No module named setuptools
Storing complete log in /Users/brendanspillane/Library/Logs/pip.log
localhost:~ brendanspillane$
I believe the Python/2.6 is the issue here. As a result i tried to set my Python Path (my first time) Using this question as a reference "changing python path on mac?" i typed in
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
This has no apparent effect.
However I am still not able to run sudo pip install distribute and keep getting the same error.
Can anyone help me? Is it my Python Path? or am I looking in the wrong direction?
Any help is as always, much appreciated.
Deepend

I'm not really sure how it worked but it did. #Robert Lujo deserves the up votes for his answer at https://stackoverflow.com/a/16511140/1214163
If the answer is also added here i will accept it.

Related

Anaconda installed but No module named 'conda' after installing flake8

While trying to install atom-lint package in Atom editor I somehow corrupted my conda installation.
I did the following things that might have caused the issue:
Installed a python dependency Flake8 using conda install.
Messed around with Atom Init Script (I can provide more info if needed)
After I did these things I encountered the following problem:
If I run conda I get
$ conda
Traceback (most recent call last):
File "/Users/me/miniconda3/bin/conda", line 12, in <module>
from conda.cli import main
ModuleNotFoundError: No module named 'conda'
Strangely enough if I run python in my command line anaconda still seems to be installed an working.
$ python
Python 3.7.1 (default, Oct 23 2018, 14:07:42)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
I have also noticed that the Python3 bin has disappeared from the conda environment folder ~/miniconda3/envs/my_env/bin/
This is very strange and I thought might be related.
Any help would be much appreciated.
I ended up making a backup copy of the miniconda3/envs folder, reinstalling miniconda and copying the environment back in. It works now, not sure what caused the issue.

ImportError: No module named 'paramiko'

I have done through the other questions online here, and I feel that mine is different enough to warrant a new question.
So I have a Centos 6 box, which is running a small website for me, acts as an office git server and I am trying to configure Python3 on it.
So I followed the following these steps to set up python3 on the server. However it seems that I cannot import paramiko into my script.
I downloaded the paramiko rpm however I get this message:
When I try to import paramiko I get:
[root#GIT Python-3.4.2]# rpm -ivh /usr/lib/Python-3.4.2/Modules/python-paramiko-1.7.5-2.1.el6.noarch.rpm
Preparing... ########################################### [100%]
package python-paramiko-1.7.5-2.1.el6.noarch is already installed
When I run python3 directly:
[root#GIT inserv_health_check]# python3
Python 3.4.2 (default, Jan 21 2015, 06:28:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paramiko
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'paramiko'
>>>
I am sure there is a simple solution to this problem perhaps the path is wrong, or I should have put a symbolic link in somewhere. Any help would be appreciated :)
Before anyone asks, which python output:
[root#GIT Python-3.4.2]# which python
/usr/bin/python
[root#GIT Python-3.4.2]# which pytho~n3
/usr/bin/which: no pytho~n3 in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root#GIT Python-3.4.2]# which python3
/usr/local/bin/python3
Thanks
You need to do pip install paramiko so that python sees that module. If you work on a virtual environment, you need to workon <env_name> first and then pip install the desired module.
type pip3 install paramiko
if you want to install it for python3

Python can't find openCV

I just ran the script to install OpenCV. I'm running Linux here. I installed it after much struggle but it finally has completed. That being said, for some reason, it still isn't working. I've never had this much trouble installing a package in my life. Here are the last few lines of my terminal:
**********************************************************************
Done. The new package has been installed and saved to
/home/myname/Desktop/OpenCV/opencv-2.4.9/build/build_20140812-1_i386.deb
You can remove it from your system anytime using:
dpkg -r build
**********************************************************************
OpenCV 2.4.9 ready to be used
me:~/Desktop$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
anyone have any ideas why it's not working?
thanks
From openCV - python installation manual:
After installing:
Installation is over. All files are installed in /usr/local/ folder. But to use it, your Python should be able to find OpenCV module. You have two options for that.
Move the module to any folder in Python Path : Python path can be found out by
entering import sys;print sys.path in Python terminal. It will print out many locations. Move /usr/local/lib/python2.7/site-packages/cv2.so to any of this folder. For example,
su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/site-packages
But you will have to do this every time you install OpenCV.
Add /usr/local/lib/python2.7/site-packages to the PYTHON_PATH: It is to be done only once. Just open ~/.bashrc and add following line to it, then log out and come back.
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
Thus OpenCV installation is finished. Open a terminal and try import cv2.
Note that your python version or library location may be different.

I can't call pymongo in the python shell

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.

Using twisted on OS X Mavericks

I am trying to use twisted on OS X Mavericks, but I get this error message when I try to import it.
christohersmbp2:~ christopherspears$ python
Python 2.7.6 (default, Mar 8 2014, 09:29:01)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twisted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named twisted
My guess is that I am receiving this error because I am not using the default Python. I am using a Python installed with brew. Ideally, I would want to install twisted into a virtual environment to play with, but the docs are seriously lacking in details. Apparently, a dmg exists for Mac OS X 10.5, which is not helpful for me. I can install from the tarball into the virtual environment, but I am not sure how to do this. Any hints?
If you're using virtualenv, it doesn't matter whether you are using the system python or not.
Simply pip install twisted in your virtualenv, like:
$ workon MyTwistedEnv
$ pip install twisted
Currently, due to a bug in Xcode that affects all projects which contain extension modules, you may need to spell this
$ CFLAGS= pip install twisted
instead; hopefully this will be fixed soon. It may not affect brew installed Pythons, however.

Categories