ImportError: No module named 'ldap' Python 3.5 - python

I'm running Python 3.5 (on Windows) and I have installed python-ldap from https://pypi.python.org/pypi/python-ldap/
I also tried using ldap3 but I keep getting an error saying
"ImportError: No module named 'ldap'
I looked around and saw some people saying there's no python-ldap for 3.5 so I installed 2.6 still getting the same error.
Is there a way to import ldap and make it work for Python 3.5?

Try the command below:
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap

Open a command line(cmd, powershell, git bash)
Check you python version
$ pyhton --version
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/
Download the library according with your python version and windows system
And install it on a command line using
pip install file_downloaded.whl
For example:
If you have python 3.5x and windows x64,
download the file python_ldap‑3.2.0‑cp35‑cp35m‑win_amd64.whl
pip install python_ldap‑3.2.0‑cp35‑cp35m‑win_amd64.whl

I'm running Apache Airflow on an Amazon EC2-Instance and I was getting "ImportError: No module named 'ldap3'. I used these two sites https://www.python-ldap.org/en/latest/installing.html and http://ldap3.readthedocs.io/installation.html to run the commands sudo python -m pip install python-ldap and sudo pip install ldap3 but my pip wasn't working for the last command so after some investigation I found out in my /usr/bin/ directory I had pip, pip-2.7, pip-3.6, and pip-python so I changed the command to pip-3.6 install ldap3 and then everything worked! Hope this helps someone.

I tried multiple approaches but finally, PyPI official documentation fixed this.
I was trying to execute on VS Code and did pip3 install python-ldap, but it didn't solve the issue. So I did the below from VS Code
# %% - This runs the below code as a Jupyter notebook cell
!pip3 install python-ldap
Now, I am able to import ldap and use it

Inside you folder, you can use virtualenv for python 3, example:
/opt/python-ldap-test
virtualenv -p /usr/bin/python3.5 venv
source venv/bin/activate
and then
pip install ldap3

It's extremely complicated to make things from 2.X to work in 3.X. Have you tried using it in a separate, 2.X only script and using it from there? It's not so unusual to combine python 2.X with 3.X in that manner or so I've heard.

Related

Cannot install pip on Python 2.7

I'm a new Python user. I'm having issues installing new modules for python 2.7. When I try installing a new module from PyCharm, I get the following error
Error: Python packaging tool 'pip' not found
Moreover, I'm a bit confuse about which Python version I'm actually using...
This is what I get when I type the following commands in the terminal.
$ which python
/usr/bin/python
$ echo $PYTHONPATH
PYTHONPATH:/usr/local/lib/python3/dist-packages/
$ python -V
Python 2.7.6
Everything seems a bit messed up to me...all the procedures I follow to install pip result in failure. The command
$ python get-pip.py
returns
You are using pip version 7.1.0, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command
However, when I run that command, it tells me that there is no module named pip.
Please, how can I fix it? I need to work with Python 2.7 but I'm completely unable to install packages. Thanks.
EDIT I am using Ubuntu 14.04 LTS
You may be trying to install pip wrong. Depending on your version of linux there are several install methods that can be found here
for your version judging by your use of get.
try this one:
sudo apt-get install python-pip

Python 2.7: No module named setup tools

I am trying to clone and install the keras package from github. When I run sudo python setup.py install, it says no module named setuptools. I looked at some posts that were for python 3; however, this solutions did not work for me. I am working on a terminal from a windows computer. I am using python 2.7. I tried the following commands: python -m pip install -U pip setuptools from this website: https://packaging.python.org/installing/. However, nothing seemed to work.
If you are working on Windows then you should be typing batch commands, not bash (Linux, OSX), therefore, sudo ... should not be used by you.
Firstly, I would recommend to install pip, it will make package update and installation a lot easier. Save it as get-pip.py and run the following in the directory the file is located python get-pip.py. Official pip website.
Then install upgrade pip which will also install the latest versions of setuptools and wheel with this python -m pip install -U pip setuptools.

can't import libraries installed in python

I usually try to install libraries for python by :
sudo apt-get install python-lib name
and when the operation is complete I can't import the library I have tried this for pygame,tk and other libs. I also usually can't install any library with pip because it gives me a bunch of error and I have also tried installing packages with their source by :
python setup.py build
python setup.py install
and usually I get errors on the "build" part.
What should I do?
Are you using Ubuntu? Probably yes. Ubuntu have two versions of python preinstalled: python2.7 and python3.4. Your command is installing library for python2.7. If you are writing your script for python 3.4, then you fail with import libraries. Try using sudo apt-get install python3-packagename to install library for python3.
edit:
are you using your pip command with sudo? sudo pip instal ...?

Installing & running modules in Python 3 (Beginner)

I am very new to the world of coding, so I will try to provide as much information as i can regarding to my question.
Essentially, I wanted to install a module (moviepy) for Python 3. The site were I found the module suggested I use pip to unpack and install the module, so I did.
In my terminal, I entered pip install moviepy and pip proceeded to unpack and install my module, yay!
I then went over to my IDLE to see if the module would import, import moviepy, but received this error:
ImportError: No module named 'moviepy'
Huh? I thought I had just installed moviepy?
Upon further investigation, the module appears to have been written to my Python 2.7 site-packages folder and not my in Python 3 site-packages folder.
So my question is: How can I get my module to install to Python 3?
The modules website says that it is compatible with Python 3.
Im assuming this is a file path issue of some kind, but i don't know where to begin.
I'm currently using a OS X Yosemite version 10.10.2, Python 2.7.6, Python 3.5.0
Any help or comments are greatly appreciated here!
Help the n00b!
If you are using python in linux you must run pip with python3:
python3 -m pip install moviepy
according to python official doc :
On Linux, Mac OS X and other POSIX systems, use the versioned Python
commands in combination with the -m switch to run the appropriate copy
of pip:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
Since pip itself is written in python , you could simply run the following in your terminal:
/path/to/python3 /usr/bin/pip install foo
More info:
To install pip, securely download get-pip.py
Run the following (which may require administrator access):
/path/to/python3 get-pip.py
Try below version of moviepy
pip install moviepy==0.2.3.5

No module named 'pymysql'

I'm trying to use PyMySQL on Ubuntu.
I've installed pymysql using both pip and pip3 but every time I use import pymysql, it returns ImportError: No module named 'pymysql'
I'm using Ubuntu 15.10 64-bit and Python 3.5.
The same .py works on Windows with Python 3.5, but not on Ubuntu.
Sort of already answered this in the comments, but just so this question has an answer, the problem was resolved through running:
sudo apt-get install python3-pymysql
Use:
import pymysql
Not:
import PyMySQL
That works for me.
After trying a few things, and coming across PyMySQL Github, this worked:
sudo pip install PyMySQL
And to import use:
import pymysql
If even sudo apt-get install python3-pymysql does not work for you try this:
Go to the PyMySQL page and download the zip file.
Then, via the terminal, cd to your Downloads folder and extract
the folder
cd into the newly extracted folder
Install the setup.py file with: sudo python3 setup.py install
Make sure that you're working with the version of Python that think you are. Within Python run import sys and print(sys.version).
Select the correct package manager to install pymysql with:
For Python 2.x sudo pip install pymysql.
For Python 3.x sudo pip3 install pymysql.
For either running on Anaconda: sudo conda install pymysql.
If that didn't work try APT: sudo apt-get install pymysql.
If all else fails, install the package directly:
Go to the PyMySQL page and download the zip file.
Then, via the terminal, cd to your Downloads folder and extract the folder.
cd into the newly extracted folder.
Install the setup.py file with: sudo python3 setup.py install.
This answer is a compilation of suggestions. Apart from the other ones proposed here, thanks to the comment by #cmaher on this related thread.
To get around the problem, find out where pymysql is installed.
If for example it is installed in /usr/lib/python3.7/site-packages, add the following code above the import pymysql command:
import sys
sys.path.insert(0,"/usr/lib/python3.7/site-packages")
import pymysql
This ensures that your Python program can find where pymysql is installed.
fwiw, for a conda env:
conda install -c anaconda pymysql
For windows or one using google colab, you can try this
!pip install pymysql
import pymysql
sudo apt-get install python3-pymysql
This command also works for me to install the package required for Flask app to tun on ubuntu 16x with WISG module on APACHE2 server.
BY default on WSGI uses python 3 installation of UBUNTU.
Anaconda custom installation won't work.
I had this same problem just now, and found the reason was my editor (Visual Studio Code) was running against the wrong instance of python; I had it set to run again python bundled with tensorflow, I changed it to my Anaconda python and it worked.
Just a note:
for Anaconda install packages command:
python setup.py install
if you are using SPYDER IDE , just try to restart the console or restart the IDE, it works
I also got this error recently when using Anaconda on a Mac machine.
Here is what I found:
After running python3 -m pip install PyMySql, pymysql module is under /Library/Python/3.7/site-packages
Anaconda wants this module to be under /opt/anaconda3/lib/python3.8/site-packages
Therefore, after copying pymysql module to the designated path, it runs correctly.
Another common issue causing the error message to appear is related to conda environments in jupyter notebook and jupyter lab.
After successfully installing a module (pymysql in this case) in one environment, import may seem to fail because the environment has not been correctly registered. To solve this it is necessary to manually add kernels for each environment.
Solution and more details can be found here.
I tried installing pymysql on command prompt by typing
pip install pymysql
But it still dont work on my case, so I decided to try using the terminal IDE and it works.
I ran into the same problem earlier, but solved it in a way slightly different from what we have here. So, I thought I'd add my way as well. Hopefully, it will help someone!
sudo apt-get install mysql-client didn't work for me. However, I have Homebrew already installed. So, instead, I tried:
brew install mysql-client
Now, I don't get the error any more.
You can also visit this lien pip install PyMySQL
You just need to install:
python3 -m pip install PyMySQL
The following pymysql version worked for me:
pip install pymysql==1.0.2
For anaconda user,
I got this error message.
ModuleNotFoundError: No module named 'pymysql'
So tried 'pip install pymysql' but got below.
Requirement already satisfied: pymysql
What worked for me is,
python file.py (NOT py file.py)

Categories

Resources