If I create a setup.py using requires, Pip doesn't install my dependencies.
Here's my setup.py:
from distutils.core import setup
setup(name='my_project',
description="Just a test project",
version="1.0",
py_modules=['sample'],
requires=['requests'])
I wrote a simple sample.py:
import requests
def get_example():
return requests.get("http://www.example.com")
I then try to install it:
$ pip install -e . [15:39:10]
Obtaining file:///tmp/example_pip
Running setup.py egg_info for package from file:///tmp/example_pip
Installing collected packages: my-project
Running setup.py develop for my-project
Creating /tmp/example_pip/my_venv/lib/python2.7/site-packages/my-project.egg-link (link to .)
Adding my-project 1.0 to easy-install.pth file
Installed /tmp/example_pip
Note that requests, my dependency isn't installed. If I now try to use my test project:
$ python [15:35:40]
>>> import sample
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/example_pip/sample.py", line 1, in <module>
import requests
ImportError: No module named requests
What am I doing wrong?
The correct spelling is install_requires, not requires; this does require that you use setuptools, not distutils:
from setuptools import setup
setup(name='my_project',
description="Just a test project",
version="1.0",
py_modules=['sample'],
install_requires=['requests'])
I can recommend the Python Packaging User Guide for the nitty gritty details.
Related
I'm using Heroku as a development server. When I try to push my Django application to Heroku it first tries to install my packages from the requirements.txt file.
requests==2.18.3
ssh-import-id==5.5
The problem is I have a dependency on one of my packages with others. In the above packages, ssh-import-id needs requests package already installed. So when I push the app, pip fails to install and stops the deployment.
Collecting requests==2.18.3 (from -r re.txt (line 1))
Using cached https://files.pythonhosted.org/packages/ba/92/c35ed010e8f96781f08dfa6d9a6a19445a175a9304aceedece77cd48b68f/requests-2.18.3-py2.py3-none-any.whl
Collecting ssh-import-id==5.5 (from -r re.txt (line 2))
Using cached https://files.pythonhosted.org/packages/66/cc/0a8662a2d2a781db546944f3820b9a3a1a664a47c000577b7fb4db2dfbf8/ssh-import-id-5.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-go0a5mxf/ssh-import-id/setup.py", line 20, in <module>
from ssh_import_id import __version__
File "/tmp/pip-install-go0a5mxf/ssh-import-id/ssh_import_id/__init__.py", line 25, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-go0a5mxf/ssh-import-id/
I need to install all the listed packages using pip in single attempt. Because by default Heroku runs, pip install -r requirements.txt.
This is a bug.
The library's setup.py imports the library to get the version for inclusion in the setup() function call...
import os
from setuptools import setup
from ssh_import_id import __version__
... and the library tries to import requests which doesn't yet exist in the environment. This is ssh_import_id.__init__.py:
import argparse
import json
import logging
import os
import platform
import requests # <=== here
import stat
import subprocess
import sys
import tempfile
A fix has been added which works around needing to import the package to get the version...
import os
from setuptools import setup
import sys
def read_version():
# shove 'version' into the path so we can import it without going through
# ssh_import_id which has deps that wont be available at setup.py time.
# specifically, from 'ssh_import_id import version'
# will fail due to requests not available.
verdir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "ssh_import_id"))
sys.path.insert(0, verdir)
import version
return version.VERSION
... but the fix isn't in the current pypi version 5.6.
You could install latest master branch from source instead of pypi by changing your requirements.txt to something like:
-e git+https://git.launchpad.net/ssh-import-id#egg=master
Im trying to install and use stats_exporter from opencensus.ext.stackdriver using the following guide: opencensus-ext-stackdriver
after installing it through pip:
pip install opencensus-ext-stackdriver
Im trying to import it and:
from opencensus.ext.stackdriver import stats_exporter as stackdriver
ImportError: cannot import name 'stats_exporter' from 'opencensus.ext.stackdriver'
When comparing the Git repo, and my local venv/lib/python3.7/site-packages/... it seems like the pip version isn't compatible with Github , so i tried to install it though cloning, and using setup.py
pip install ../opencensus-python/contrib/opencensus-ext-stackdriver/dist/opencensus-ext-stackdriver-0.2.dev0.tar.gz
which gives me the following error:
(venv) Yehoshaphats-MacBook-Pro:present-value yehoshaphatschellekens$ pip install ../opencensus-python/contrib/opencensus-ext-stackdriver/dist/opencensus-ext-stackdriver-0.2.dev0.tar.gz
Processing /Users/yehoshaphatschellekens/opencensus-python/contrib/opencensus-ext-stackdriver/dist/opencensus-ext-stackdriver-0.2.dev0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/s2/y6vcdc1105s8xlpb12slr9z00000gn/T/pip-req-build-7m1ibdpd/setup.py", line 17, in <module>
from version import __version__
ModuleNotFoundError: No module named 'version'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/s2/y6vcdc1105s8xlpb12slr9z00000gn/T/pip-req-build-7m1ibdpd/
Similar errors of this type indicated that i need to upgrade setuptools, tried that also :(
This post suggests that it might related to the fact that i'm using python3, which isn't completable with version though i really need to install this package on my python3 venv.
Any Help on this issue would be great!
Try this:
#!/usr/bin/env python
import os
from opencensus.common.transports.async_ import AsyncTransport
from opencensus.ext.stackdriver import trace_exporter as stackdriver_exporter
from opencensus.trace import tracer as tracer_module
from opencensus.stats import stats as stats_module
def main():
sde = stackdriver_exporter.StackdriverExporter(
project_id=os.environ.get("PROJECT_ID"),
transport=AsyncTransport)
tracer = tracer_module.Tracer(exporter=sde)
with tracer.span(name='doingWork') as span:
for i in range(10):
continue
if __name__ == "__main__":
main()
and
grpcio==1.19.0
opencensus==0.3.1
opencensus-ext-stackdriver==0.1.1
NB The OpenCensus libraries need gRPC too.
You will need:
a GCP Project and it's Project ID (${PROJECT_ID})
a service account with roles/cloudtrace.agent and its key.
Then:
virtualenv venv
source venv/bin/activate
export PROJECT_ID=[[YOUR-PROJECT-ID]]
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/key.json
pip3 install --requirement requirements.txt
python3 stackdriver.py
i am trying to install through windows power shell and i get this error
C:\Users-\desktop\dist\twitter-1.10.0> python setup.py install
Traceback (most recent call last):
File "setup.py", line 1, in
from setuptools import setup, find_packages
ImportError: No module named setuptools
PS C:\Users-\desktop\dist\twitter-1.10.0>
any help is appreciated.
As the Traceback says, you have no setuptools module installed. You can download it here and install it invoking python ez_setup.py from the directory where you have downloaded the file.
I've recently installed the latest version of Py2app on my Mac Os X (10.5.8), and I've watched some tutorials on YouTube such as: http://www.youtube.com/watch?v=Zip9H_dLdhI, and http://www.youtube.com/watch?v=5Ehhts9HhE8, but when I copy their main setup code, it gives me an ImportError:
Traceback (most recent call last):
File "/Users/CarlProject/Rectangles Backup.py", line 7, in <module>
from setuptools import setup
ImportError: No module named setuptools
This is my setup code, copied and edited from the first YouTube video:
"""
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['Rectangles.py']
DATA_FILES = [('', ['fonts'])]
setup(
app = APP,
data_files = DATA_FILES,
setup_requires = ['py2app'],
)
My Python version is 2.7.5, and I'm using Pygame. The Py2app is the latest: 0.7.3. Yes, everything is on my desktop, and I've installed setuptools 0.9.8 Help!
Just incurred in the same problem but found the solution.
"For ease of distribution, you may wish to have your setup.py script automatically ensure that setuptools is installed. This requires having a copy of ez_setup in your project, which can be obtained from here:"
http://peak.telecommunity.com/dist/ez_setup.py
(Save it in your project directory with .py extension)
"Once this is done, you simply add the two line ez_setup preamble to the very beginning of your setup.py:"
import ez_setup
ez_setup.use_setuptools()
Source: https://pythonhosted.org/py2app/examples.html
You need to install setuptools.
Download it from here and then check this out to learn how to install it:
Python Setuptools, easy_install setup mac
I was trying to find libraries that would help me for auto form filling . Someone suggested me Grab(a site scraping library) from http://pypi.python.org/pypi/grab/0.4.8 . I uncompressed tar.gz and then tried the following ,
python setup.py install
Traceback (most recent call last):
File "setup.py", line 1, in <module>
from setuptools import setup, find_packages
ImportError: No module named setuptools
Does anyone know how to install it ?
Error is clear and simple.
ImportError: No module named setuptools
Please check, if you've installed setuptools for python3 or python2.
An example on archlinux, (python => python3), (python2 => python2)
Be careful with that
Please try with "python2 setup.py install"