N00b Altert.
So I tried to call "import requests" through Python and got the error:
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
I do not think I have pip installed correctly or at all?
easy_install requests returns:
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-6488.pth'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Library/Python/2.7/site-packages/
Any help on this would be greatly appreciated... I have seen the other posts with users mentioning the same but it doesn't seem to help.
According to the requests website installation page:
Checkout the git repository
execute /path/to/virtualenv/bin/python requests/setup.py install
As a third step, if you have problems doing this, please come back and leave a comment, such that I may help you further.
Your problem is a permissions problem. The solution I'd recommend is to pip install virtualenv and create a new environment for your project, installing requests in that environment.
To install pip, do a curl -kO https://bootstrap.pypa.io/get-pip.py and run it as python get-pip.py then install virtualenv as in the above paragraph.
Type
import requests
Guide your cursor to the command (Donot press space) You will see a red bulb.There will be an option to install requests. Click it and done.
This worked for me on Pycharm. Installing it through pip didnot help me.
Related
I am trying to run OpenCV with PyPy, I tried everything to make it work, but so far I couldn't. Tried downloading opencv-python from its github repository (https://github.com/skvark/opencv-python) and then running setup.py myself, but it gives me this error:
Traceback (most recent call last): File "C:\pypy2.7-v7.1.1-win32\site-packages\skbuild\setuptools_wrap.py", line 578, in setup
cmkr.make(make_args, env=env)
File "C:\pypy2.7-v7.1.1-win32\site-packages\skbuild\cmaker.py", line 481, in make
os.path.abspath(CMAKE_BUILD_DIR())))
An error occurred while building with CMake.
Command:
"cmake" "--build" "." "--target" "install" "--config" "Release" "--"
Source directory:
I:\Dropbox\project\opencv-python
Working directory:
I:\Dropbox\project\opencv-python\_skbuild\win32-2.7\cmake-build
Please see CMake's output for more information.
Tried running the command separately, but also gives me another error:
Error: could not load the cache.
- Also tried some solutions for that cache error but nothing.
I couldn't understand what was the issue, and also couldn't find any CMake output file. Any help is appreciated.
When I try the following on linux, I get nice cmake output. Perhaps you do not have cmake installed and on your path?
virtualenv -p /path/to/pypy2/bin/pypy /tmp/pypy2
source /tmp/pypy2/bin/activate
sudo apt install libtiff-dev libqt4-dev
python setup.py bdist_wheel
I have no idea with installing by pypy, but I can give you some tips to install
1- install with pip:
a- make sure yourself that python directory has write permission
b- open cmd in administrative permission
c- run the command pip install opencv-contrib-python
2- install through whl files, search for python binary files and
install it locally(while installation you should have internet
connection)
Edit: Yes I know this question already exists, except my question is a bit different and none of the solutions fixed it.
I do most of my Python stuff when I'm at work and not on my personal machine, but I decided to install it on my personal computer as well. I fresh installed python 3.6.1, and created a virtual environment with virtualenv. Then within the virtualenv I tried to pip install urllib (or any module) and I received the error:
(pdbot) C:\Users\user\Documents\pdbot>pip install urllib
Collecting urllib
Using cached urllib-1.21.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\setup.py", line 191
s.connect((base64.b64decode(rip), 017620))
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\
I read elsewhere that this error had something to do with setuptools not being properly installed. So I ran this to attempt to fix the issue:
easy_install -U setuptools
I ended up receiving an even weirder error next:
(pdbot) C:\Users\zeke\Documents\pdbot>easy_install -U setuptools
Searching for setuptools
Reading https://pypi.python.org/simple/setuptools/
Downloading https://pypi.python.org/packages/a9/23/720c7558ba6ad3e0f5ad01e0d6ea2288b486da32f053c73e259f7c392042/setuptools-36.0.1.zip#md5=430eb106788183eefe9f444a300007f0
Best match: setuptools 36.0.1
Processing setuptools-36.0.1.zip
Writing C:\Users\zeke\AppData\Local\Temp\easy_install-jhg1val_\setuptools-36.0.1\setup.cfg
Running setuptools-36.0.1\setup.py -q bdist_egg --dist-dir C:\Users\zeke\AppData\Local\Temp\easy_install-jhg1val_\setuptools-36.0.1\egg-dist-tmp-8apak7kn
warning: no files found matching '*' under directory 'setuptools\_vendor'
Copying setuptools-36.0.1-py3.6.egg to c:\users\zeke\documents\pdbot\lib\site-packages
Adding setuptools 36.0.1 to easy-install.pth file
Installing easy_install-script.py script to c:\users\zeke\documents\pdbot\Scripts
Installing easy_install.exe script to c:\users\zeke\documents\pdbot\Scripts
error: [WinError 5] Access is denied: 'c:\\users\\zeke\\documents\\pdbot\\Scripts\\easy_install.exe'
This looks like a permissions error, but I ran these both in an administrator command prompt (Windows 10) and got the same result. I am the only user on this computer and I have all admin permissions. Is this virtualenv causing an issue? How do I remedy it?
EDIT: I was able to fix the permissions issue by leveraging the python executable like so:
python -m easy_install -U setuptools
But it didn't fix the python setup.py egg_info issue. I still get this error message when trying to pip install anything:
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\
I have tried both python -m pip install urllib and pip install urllib and neither work.
I had the same problem when trying to install urllib, but after doing a pip search urllib, I discovered that the problem was due to the version of urllib. From the search:
$ pip search urllib
...
> urllib5 (5.0.0) - Just increment the number and create a new lib. Never fix the original one.
At the end, a simple
pip install urllib5
within an elevated shell solved it.
Your problem has to do with permissions. The related/similar tools setup_tools, easy_install, and pip all tend to set a default set of permissions on files and folders they try to create in the package installation folder(s), rather than trying to match access permissions of the location they're installing in.
On Linux systems, where files and folders individually have permissions, this is frequently bypassed with the sudo command. On Windows, the equivalent is to run the installer as an Administrator. Since you're in the console, you have to open a console with Administrator privileges to run the pip command in.
Notable under Windows, the modules installed with pip from an Administrator console are still accessible to all users of the system that have the proper path in the PYTHONPATH system environment variable. Under Linux however, the problem is exacerbated by the fact that the files themselves may not be created with read and execute access for other users and may need to have their permissions manually modified after installation.
WARNING: urllib vs urllib2 vs urllibx
Both other answers claim that the problem is you're not specifying the correct "version" of the module in the call to pip. Neither is correct, as the error clearly indicates an installation folder access permissions violation causing the failure, but they also incorrectly recommended VERY unsafe behavior.
pip install urllib != pip install urllib5 these are two completely different packages.
The documentation for pip (https://packaging.python.org/tutorials/installing-packages/#id17) clearly says the way to specify a module version explicitly is pip install 'urllib==5'.
As part of how the package management engine implemented by pip works, running the command pip install urllib will always try to use the latest version of the urllib package, so you shouldn't need to specify the version unless you have some reason that you need a very specific version of the module.
There are two points to make in order to answer your question:
1. You are lucky you did not install that package!
The package you were trying to install was a maliciously created python package that was designed to look like a real package (in this case urllib3). If you had installed it, the package would have operated as normal except it would have sent some basic information about the system on which you installed the package to a URL (you can see more details on this here). You can read more about this fake package at either of the following links:
https://app.threatconnect.com/auth/incident/incident.xhtml?incident=5256822&owner=Common%20Community (you can sign up for a free account to view this one)
http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/index.html
Sending basic information about your systems to an unknown source isn't the worst thing you could do, but is certainly something you want to avoid when possible.
2. To properly install a package...
Specifically urllib:
To install urllib, you need to specify the version of the package you would like to install. For example, pip install urllib3.
Any package in general:
As #Elisabete Coelho suggested, you can use the pip search <package-name> feature to view the available packages. This is not perfect, however, as it may list malicious libraries like the one you were trying to install. A good guideline is that you should follow the installation instructions in a package's documentation closely to avoid any unforeseen issues. This is just an unfortunate necessity of living in a world where people make pretend python packages.
I'm using Amazon linux, and I followed some steps for using letsencrypt that easily found in google search, but all it fails with:
Error: couldn't get currently installed version for /root/.local/share/letsencrypt/bin/letsencrypt:
Traceback (most recent call last):
File "/root/.local/share/letsencrypt/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/root/.local/share/letsencrypt/local/lib/python2.7/dist-packages/certbot/main.py", line 11, in <module>
import zope.component
File "/root/.local/share/letsencrypt/local/lib/python2.7/dist-packages/zope/component/__init__.py", line 16, in <module>
from zope.interface import Interface
ImportError: No module named interface
What I do is:
# git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
# /opt/letsencrypt/letsencrypt-auto --debug
That's it. So I tried to fix this, but dozens of solution that I found all won't worked to me.
Most of them said try this:
unset PYTHON_INSTALL_LAYOUT
But still got same error, nothing changes. And someone said that type this:
pip install --upgrade pip
But after typed that, I can't use pip anymore, it failed with some kind of command not found error, so I had recreated my server again.
I also tried to use CertBot, but it gives me exactly same error!
I'm using Linux 4.4.51-40.58.amzn1.x86_64 x86_64, need a help. I spent almost a day, but nothing progressed.
Every solution that I was found were not worked to me. Any advice will very appreciate it.
Removing certbot directory did the trick for me.
rm -rf /opt/eff.org/certbot/
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
sudo ./certbot-auto certonly --standalone -d example.com --no-bootstrap
I had same issue and after a long run, a very simple thing solved this issue on my AWS instance:
Move the letsencrypt cache files to another folder (considering you run it as root/sudo):
sudo mv /root/.local/share/letsencrypt /root/.local/share/letsencrypt-old
Downloaded a brand new version of letsencrypt
git clone https://github.com/letsencrypt/letsencrypt
Run the letsencrypt command to test if its working again:
sudo ./letsencrypt-auto --debug
During my search for a solution I also updated pip which might have helped. Although my attempts after pip update did not solved my issue in the same way as cleaning up the letsencnrypt cache folder.
I hope this helps. If not, some links I can share about same issue:
certbot zope.interface error
no module named interface
letsencrypt failed with no module named interface
Part of the issue for me was related to some strange default behavior around 64 bit packages installing, but not being picked up by python. After getting this issue [it's mostly installed at this point], run the following
cd /root/.local/share/letsencrypt
\cp -r ./venv/lib64/* ./venv/lib/
Then retry the command. The install locations of the python virtual environment change with different versions and operating systems, but the general principle has helped me debug two different installs.
I have also faced this issue multiple times and every time I have to repeat these following steps:
Remove cache:
sudo rm -rf /root/.local/share/letsencrypt/
sudo rm -rf /opt/eff.org/certbot/`
then,
unset PYTHON_INSTALL_LAYOUT
Install Let’s Encrypt by cloning the github repository into /opt/letsencrypt
git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
then run installer again
/opt/letsencrypt/letsencrypt-auto --debug
these steps always works for me.
I solved it following the next steps
Download certbot-auto by going to this link.
Delete letsencrypt folder:
sudo rm -rf /opt/eff.org/
Install cryptography module:
sudo python -m pip install cryptography
Run certbot-auto --debug
sudo ./certbot-auto --debug
I am unable to import the sqlite3 module in Python, version 3.5.0. Here's what I get:
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
I know, I know, there are PLENTY of StackOverflow posts and support forums across the web where people complain about this problem, but none of the posted solutions have worked for me so far. Here's where I've been:
I also have Python 2.6.6 installed on this server, which is running CentOS 6.8 x86_64. I can open up the Python REPL and import sqlite3 just fine when using Python 2.6.6. I can also use sqlite3 from straight from bash and nothing seems awry.
This helpful question looked promising. I tried to re-configure and re-compile Python3.5 with the --enable-loadable-sqlite-extensions option, as user jammyWolf suggested. Nope, same error still occurs.
I've been using virtual environments like a good boy, but I have root access to this server. So, I was a bad boy and ran python3 as root without any virtualenvs activated. Still no luck. So I don't think it has anything to do with permissions.
I noticed that in the error message, it says No module named '_sqlite3'. This thread suggests that the underscore before the module name means that the module is an implementation detail, and isn't exposed in the API. ... I'm not sure what to make of this information, but there may be a hint somewhere in there.
Any ideas?
Falsetru is correct, I am going to go into a bit more detail for those not familiar (linux instructions). If you are getting this error, chances are you are using a version of python that was compiled without the correct headers. Here's a step by step guide to get it sorted. (Python 3.X.X instructions)
Install the required sqlite libraries
sudo apt-get install libsqlite3-dev
Uninstall python (I'm using python 3.6.5 as an example in this guide)
sudo apt-get remove python3.6
Download python from source
cd /tmp && wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
Unpack the archive
tar -xvf Python-3.6.5.tgz
Configure
cd Python-3.6.5 && ./configure
Make and install (and go make coffee while you're at it)
make && sudo make install
If you did everything correctly running "python3.6 -V" should give you your python version. Note you will have to rebuild any virtual environments you have as well.
One final caveat you may encounter.
zipimport.ZipImportError: can't decompress data; zlib not available
This happens if you don't have the following zlib library installed:
sudo apt-get install zlib1g-dev
Install sqlite-devel package which includes header, library that is required to build sqlite3 extension.
yum install sqlite-devel
NOTE: Python does not include sqlite3 library itself, but an extension module (wrapper).
I copied sqlite3.dll to this folder:
C:\Users\*****\Anaconda3\DLLs
It worked after two weeks trying everything else.
I have installed the Emacs package jedi-emacs using M-x package install
and the following Python packages:
Jedi
EPC
argparse
using:
pip install --install-option="--prefix=~/.my_python_packages/" jedi
pip install --install-option="--prefix=/.my_python_packages/" epc
pip install --install-option="--prefix=/.my_python_packages/" argparse
since I do not have root priviledges.
When I open a Python file, I get the following error in the minibuffer, no matter where I place the cursor:
deferred error : (error Server may raise an error : Traceback (most recent call last):
File "/home/avazquez/.emacs.d/elpa/jedi-20130119.830/jediepcserver.py", line 261, in <module>
)
What could be causing it?
This is with Emacs 24.2.1
I found the solution to my problem. I did not have PYTHONPATH set up correctly (it should include the corresponding paths for /path/to/custom-packages).
For more info on this issue see the corresponding ticket in the package repository for emacs-jedi.