Unable to download mongo-connector using pip - linux

I am trying to install mongo-connector on Amazon-EC2 instance using the following command:
pip install mongo-connector
But following error flashes up everytime:
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 31 7, in run
prefix=options.prefix_path,
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 736, in install
requirement.uninstall(auto_confirm=True)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 742 , in uninstall
paths_to_remove.remove(auto_confirm)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 1 15, in remove
renames(path, new_path)
File "/usr/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/usr/lib64/python2.7/shutil.py", line 300, in move
rmtree(src)
File "/usr/lib64/python2.7/shutil.py", line 252, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/usr/lib64/python2.7/shutil.py", line 250, in rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied: '/usr/lib/python2.7/dist-packages/request s/sessions.pyo'
I thought this might be some issue with root permissions, so I tried :
sudo pip install mongo-connector
But this says ,
sudo: pip: command not found
I am using pip 8.1.2, Python 2.7.12.
Any help would be appreciated!

I solved this by using the following command:
sudo `which pip`install mongo-connector

You shouldn't be using sudo to install packages with pip. While it works, it's modifying files that should be managed by your OS package manager which isn't desirable -- see also https://stackoverflow.com/a/21056000/1931274.
If you pass --user to that command, you'll be able to install without permission issues:
pip install --user mongo-connector
Moreover, newer versions of pip (installable via pip install --user pip or using get-pip.py) print a better, more helpful message when such errors occur.

For windows download required precompiled python packages from https://www.lfd.uci.edu/~gohlke/pythonlibs/ and pip install <point to the downloaded file>.

One more way to solve this is:
sudo bash
now you are in a bash with root privileges so now you can execute
pip install mongo-connector
without any permission issues

Related

pkg_resources.DistributionNotFound: The 'platformdirs<3,>=2' distribution was not found and is required by virtualenv

I am trying to create an isolated environment using pip, the instructions from "Hands on Machine Learning With Ski-Kit and Tensor Flow" have me run these lines of code and this is the output I get. I've tried uninstalling pipenv and that creates another error where pipenv command not found. Not sure how to work around this, can anyone help? I'm using a Mac with python3.9
Darrens-MacBook-Air:~ odonned4$ cd $ML_PATH
Darrens-MacBook-Air:~ odonned4$ virtualenv env
File "/usr/local/bin/virtualenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
#_call_aside
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside
f(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 585, in _build_master
return cls._build_from_requirements(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'platformdirs<3,>=2' distribution was not found and is required by virtualenv```
What is the problem?
You are trying to run Python 3.9, right? Well, according to your error message, it seems like you're invoking Python 2.7:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
^^^
This confusion happens because macOS added Python 2.7 to the distribution for... compatibility reasons. And, probably, you have virtualenv on that distribution, but you don't have platformdirs, so creating a virtualenv fails.
How to solve the problem?
There are many ways to clarify this confusion. A good way is using python3 -m virtualenv (instead of virtualenv). That should create a virtualenv with Python 3.
Also, you can get sure that the virtualenv package is available in your Python 3.9 installation. To identify that, see if virtualenv appears when typing python3 -m pip list. If not, run python3 -m pip install virtualenv.
The real problem here is that Mac is hard wired to use python2. When using virtualenv, you might have run the command:
$ /usr/bin/easy_install virtualenv
which should have added virtualenv to the /usr/bin/ for direct use, but to be used with the default python2 instead of python3.9 which you might have installed on your own.
A simple way around is to use
$ python3 -m virtualenv <env-name>
instead of
$ virtualenv <env-name>
Or in my case, add an alias in .bash_profile:
$ alias virtualenv="python3 -m virtualenv"
which is a duct tape solution but it works as well.
Try uninstalling setuptools with
pip uninstall -y setuptools
and reinstalling it with
pip install setuptools
OR
Upgrade setuptools with
pip install --upgrade setuptools
OR
For me i have faced this issue some before in python 3.8.
I fixed it by
sudo apt install --reinstall python3-pkg-resources python3-setuptools
OR
Uninstall virtualenv and setuptools first and find pip cache folder.
pip cache dir
Delete the cache and install virtualenv and setuptools.
I JUST SAID SOME STEPS .. TRY THIS . MAY HELP : )

Unable to install AWS CLI on a Mac

I am unable to install AWS CLI on MacBook Yosemite.
I get an error with the sudo command from AWS Documentation.
I initially installed sudo using the default python2.7, and then tried to install with python3.7 but it doesn't work. I feel it's the folder path that is incorrect but I don't know what to check on it.
Can I get some guidance?
Here is the error output:
MacBks-MBP:~ MacBkyosemite$ sudo /usr/local/bin/python3.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Password:
Running cmd: /usr/local/bin/python3.7 virtualenv.py --no-download --python /usr/local/bin/python3.7 /usr/local/aws
Running cmd: /usr/local/aws/bin/pip install --no-cache-dir --no-index --find-links file:///Users/MacBkyosemite/awscli-bundle/packages/setup setuptools_scm-1.15.7.tar.gz
Traceback (most recent call last):
File "awscli-bundle/install", line 162, in <module>
main()
File "awscli-bundle/install", line 151, in main
pip_install_packages(opts.install_dir)
File "awscli-bundle/install", line 114, in pip_install_packages
pip_script, setup_requires_dir, package
File "awscli-bundle/install", line 49, in run
p.returncode, cmd, stdout + stderr))
__main__.BadRCError: Bad rc (1) for cmd '/usr/local/aws/bin/pip install --no-cache-dir --no-index --find-links file:///Users/MacBkyosemite/awscli-bundle/packages/setup setuptools_scm-1.15.7.tar.gz': b'Traceback (most recent call last):\n File "/usr/local/aws/bin/pip", line 7, in <module>\n from pip import main\nImportError: cannot import name \'main\' from \'pip\' (/Users/MacBkyosemite/Library/Python/3.7/lib/python/site-packages/pip/__init__.py)\n'
MacBks-MBP:~ MacBkyosemite$ python3 --version
Python 3.7.3
MacBks-MBP:~ MacBkyosemite$ pip3 --version
pip 19.1.1 from /Users/MacBkyosemite/Library/Python/3.7/lib/python/site-packages/pip (python 3.7)
MacBks-MBP:~ MacBkyosemite$ which python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
To install the AWS Command Line Interface on a Mac, simply run:
sudo pip3 install awscli
Tip: It is normally a good idea to use virtual environments when installing Python libraries to avoid conflicts. In such cases, start a virtual environment, then run pip.

BeautifulSoup 4 Install Error by typing pip install --upgrade beautifulsoup4

I tried to install BeautifulSoup 4
It worked after I typed following into my mac terminal
$ easy_install beautifulsoup4
$ pip install beautifulsoup4
But when I imported it in my python,
from bs4 import BeautifulSoup
the screen always shows the Error:
ImportError: cannot import name 'HTMLParseError'
Then I googled the error and found by typing following code in terminal could solve the problem
pip install --upgrade beautifulsoup4
But after I typed,it was shown
Exception:
Traceback (most recent call last):
File "//anaconda/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "//anaconda/lib/python3.5/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "//anaconda/lib/python3.5/site-packages/pip/req/req_set.py", line 742, in install
**kwargs
File "//anaconda/lib/python3.5/site-packages/pip/req/req_install.py", line 831, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "//anaconda/lib/python3.5/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
isolated=self.isolated,
File "//anaconda/lib/python3.5/site-packages/pip/wheel.py", line 346, in move_wheel_files
clobber(source, lib_dir, True)
File "//anaconda/lib/python3.5/site-packages/pip/wheel.py", line 324, in clobber
shutil.copyfile(srcfile, destfile)
File "//anaconda/lib/python3.5/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '//anaconda/lib/python3.5/site-packages/bs4/__init__.py'
I have no idea how to fix it. Thanks for someone help
Easiest way to solve this is using Sudo.
sudo pip install --upgrade beautifulsoup4
However sudo is not always recommended to do so, you should not install arbitrary code as root.
My recommendation would be to create a virtualenv, install the packages play with before using sudo to install them as root.
You can use virtualenvwrapper
sudo pip install virtualenvwrapper
mkvirtualenv
workon
python setup.py install

Python 3 pip upgrade from 7.1.2 to 8.0.1 fails

pip says that I shall consider an upgrade. When I'm doing so and using
python -m pip install --upgrade pip
I get the following UnicodeDecode error message:
C:\Users\Sören>python -m pip install --upgrade pip
Collecting pip
Using cached pip-8.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 7.1.2
Exception:
Traceback (most recent call last):
File "C:\Users\Sören\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\basecommand.py", line 211, in main
status = self.run(options, args)
File "C:\Users\Sören\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\commands\install.py", line 311, in run
root=options.root_path,
File "C:\Users\Sören\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py", line 640, in install
requirement.uninstall(auto_confirm=True)
File "C:\Users\Sören\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_install.py", line 673, in uninstall
for path in pip.wheel.uninstallation_paths(dist):
File "C:\Users\Sören\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\wheel.py", line 512, in unique
for item in fn(*args, **kw):
File "C:\Users\Sören\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\wheel.py", line 531, in uninstallation_paths
r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD')))
File "C:\Users\Sören\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1619, in get_metadata_lines
return yield_lines(self.get_metadata(name))
File "C:\Users\Sören\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1616, in get_metadata
return self._get(self._fn(self.egg_info, name)).decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6 in position 22366: invalid start byte
You are using pip version 7.1.2, however version 8.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
I'm running Python 3 in the 32-bit version on a Windows 10 machine. I don't know if that has anything to do with it, but I had VisualStudio, version 10, installed on my system. Now it is removed.
Kind regards
John
Thanks blackpingus, your answer helped me to find the problem.
The problem was the 'ö' character, which is the name, I am using on Windows. Because of that, this name is also placed in the system path.
A workaround for that problem is to install the package using another user account, which has not any 'umlaute' in his name.
To install updated pip
From start, find the "Command Prompt
Right click on "Command Prompt"
Run as Administrator
Provide the user name and the password if prompted
Now you can upgrade pip: python -m pip install --upgrade pip

Issues installing Tweepy on Ubuntu

I'm trying to install Tweepy on an Ubuntu VM and I'm running into way more issues than I should be. My first step was to successfully get pip installed. After that I tried:
pip install tweepy
which returns:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 3020, in <module>
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 616, in _build_master
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 629, in _build_from_requirements
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 807, in resolve
pkg_resources.DistributionNotFound: pip==1.5.4
The most that I can gather from that error message is that it can't find pip version 1.5.4. However, if I ask it whereis pip it returns:
pip: /usr/local/bin/pip2.7 /usr/local/bin/pip /usr/share/man/man1/pip.1.gz
So I know pip is installed. I decided to try the other method listed and do
git clone https://github.com/tweepy/tweepy.git
cd tweepy
python setup.py install
But that only seems to partially install with error messages returning. Trying whereis tweepy after that method returns nothing.
Can anyone make sense of why this simple install isn't working for me?
This issue was resolved by using another fresh Ubuntu VM install and once again trying the manual installation by using
git clone https://github.com/tweepy/tweepy.git
cd tweepy
python setup.py install
For whatever reason, it now works. The answer is officially voodoo.

Resources