I testing my PyPI package, before upload, with pip3 install -e ., in the package directory.
It depends on pillow (import PIL in code).
When I tested with already installed pillow it worked.
But, I uninstall the pillow then reinstall my package with pip3 install -e ., it didn't work:
Obtaining file:///Users/hongbook/dev/identicon
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/hongbook/dev/identicon/setup.py", line 4, in <module>
import Identicon
File "/Users/hongbook/dev/identicon/Identicon/__init__.py", line 2, in <module>
from .Identicon import render
File "/Users/hongbook/dev/identicon/Identicon/Identicon.py", line 5, in <module>
from PIL import Image, ImageDraw
ModuleNotFoundError: No module named 'PIL'
I expected when I install that, pillow should be installed since I wrote it install_requires's value in setup.py(also that in requirements.txt):
# setup.py
from setuptools import setup, find_packages
...
setup(
name='Identicon',
version=Identicon.__version__,
...
install_requires=[
'pillow',
],
)
# requirements.txt
pillow
How can I make dependency my project to pillow right?
I think your problem is stemming from this:
version=Identicon.__version__,
In order to do that, you're importing Identicon, which is your package, which imports PIL. So, your setup.py is broken. It requires the dependencies to be already installed in order to execute, however it's the setup.py job to install those dependencies in the first place.
This is a common "chicken and egg" situation in packaging. The solution is to use a different way to parse the version number from your package, or store the version number somewhere that doesn't trigger imports of your dependencies.
You can import version without importing the entire package using imp. See how I do it in SQLObject:
from imp import load_source
from os.path import abspath, dirname, join
versionpath = join(abspath(dirname(__file__)), "sqlobject", "__version__.py")
sqlobject_version = load_source("sqlobject_version", versionpath)
setup(name="SQLObject",
version=sqlobject_version.version,
…
)
Related
I'm trying to get an in depth understanding of a bare minimum python package. As a setup.py this works perfectly:
from setuptools import setup
setup(
name='helloworld',
version='0.0.1',
description='Say hello!',
py_modules=['helloworld'],
package_dir={'': 'src'},
)
Again, I can import and run "helloworld" just fine. However, when I change "name" and "py_modules" to be something different from each other the system breaks. According to Mark Smith's EuroPython lecture "name" is what you pip install and "py_modules" is what you import.
from setuptools import setup
setup(
name='installMe',
version='0.0.1',
description='Say hello!',
py_modules=['importMe'],
package_dir={'': 'src'},
)
So I installed the software in a python virtual environment:
python3 -m venv bareMinEnv
source bareMinEnv/bin/activate
pip install -e .
and everything looked fine:
pip list
Package Version Location
---------- ------- ------------------------------------------------------------------
installMe 0.0.1 /mnt/d/PROJECTS/PACKAGE_CREATION/min2/bareMinimumPythonPackage/src
pip 20.2.3
setuptools 49.2.1
However, it breaks at the importation step. Here it show's I can't import "importMe":
>>> from importMe import say_hello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'importMe'
and here is evidence I can't import "installMe":
>>> from installMe import say_hello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'installMe'
All of this works if I keep the names the same. So how to I make them different while maintaining functionality? I've created a dozen packages and I don't understand why it's not behaving as I believe the documentation describes. Again, this is easy to fix by keeping the names the same. However, I'm trying to understand every detail about the pip packaging system. Thanks in advance.
I am trying to pip install a .whl file dynamically (the name of the file will change each time I run it) and import it from the same python script. I tried running it in a different subprocess but I am not able to access the import from within the same file. I think python's importlib might have the answer but I haven't been able to figure it out.
import subprocess
import sys
#staticmethod
def install_file(lib):
subprocess.check_call([sys.executable, "-m", "pip3", "install", lib])
# pip install the whl
install_file(whl_file_name)
# dynamically get the name of the .whl file and import it
whl = __import__(whl_file_name)
whl.do_something()
returns the following error
Traceback (most recent call last):
File "<stdin>", line 12, in <module>
ModuleNotFoundError: No module named 'name_of_whl_file'
I had a similar problem. Solved it this way:
def install_file(package: str):
subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir", "--no-index", "--find-links", "whlFolder", package], shell=True)
This method installs de package from the package name (e.g: 'tensorflow') instead of the filename, searching for the lib file in folder 'whlFolder'.
The package parameter must be informed with the package/ library name and the version (optionally). E.g:
#Installing the latest available version
install_file('tensorflow')
#Installing a specific version
install_file('tensorflow==2.2.0')
I have apache ampps which comes with version 3.6.1 of python.
I was given various directions for installing pip.
None seemed to work.
For example,
link https://packaging.python.org/tutorials/installing-packages/
says that I can run:
python -m pip install -U pip setuptools
Get a whole bunch of errors. It might amount to: no module named queue.
Similar errors happen when I download the file they mentioned (get-pip.py) and run it from python.
Now, when I look at directions for installing queue, some point me to use pip. But when I try to install pip, it is complaining that queue is not there....
Hmmm...?
Now what?
ERROR:
File "C:\Users\Nima\AppData\Local\Temp\tmp1v2hpnae\pip.zip\pip\compat\__init__.py", line 11, in <module>
File "C:\Program Files (x86)\Ampps\python\lib\logging\config.py", line 30, in <module>
import logging.handlers
File "C:\Program Files (x86)\Ampps\python\lib\logging\handlers.py", line 28, in <module>
import queue
ModuleNotFoundError: No module named 'queue'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "getpip.py", line 20061, in <module>
main()
File "getpip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "getpip.py", line 82, in bootstrap
import pip
File "C:\Users\Nima\AppData\Local\Temp\tmp1v2hpnae\pip.zip\pip\__init__.py", line 26, in <module>
File "C:\Users\Nima\AppData\Local\Temp\tmp1v2hpnae\pip.zip\pip\utils\__init__.py", line 22, in <module>
File "C:\Users\Nima\AppData\Local\Temp\tmp1v2hpnae\pip.zip\pip\compat\__init__.py", line 13, in <module>
File "C:\Users\Nima\AppData\Local\Temp\tmp1v2hpnae\pip.zip\pip\compat\dictconfig.py", line 22, in <module>
File "C:\Program Files (x86)\Ampps\python\lib\logging\handlers.py", line 28, in <module>
import queue
ModuleNotFoundError: No module named 'queue'
From the format i see here.
Firstly, pip is an installer basically what you've confused yourself with is that pip = queue which is not the case. Pip is just a packager that helps you install packages. Queue is a different module
For your case here Queue is a part of multiprocessing module so you just put this at the top of your code:
from multiprocessing import Queue
and you do not need to add import pip into your code
hope that explained things better for you :)
This line:
python -m pip install -U pip setuptools
means use pip to upgrade the installations of pip and setuptools. Only works if you already have pip - which you probably do. It is a useful step to make sure your install environment is up to date, though.
pip does in places use queue. Note it's been renamed between python2 and python3 - if you have py3, which you claim, you have queue (it was Queue in py2). So I wonder if there's a version mismatch in something.
Windows installs always create problems. You might be safer installing and experimenting with a virtualenv so your experiments don't mess up the python install from the package you mention - ampps. There are plenty of notes on that elsewhere on stackoverflow... e.g. Python and Virtualenv on Windows
pip is already included in 3.6.1, but it is in subfolder Scripts.
it is not automatically a part of the path variable.
you have to change directory and run pip or you can change environment variable so that the location of pip becomes part of the path search.
I forked the scikit-learn repository, added a file that I need and downloaded the repository. I am not sure how to use this custom library. I cd'ed to the scikit-learn-master folder and tried to use it but it throws errors. So after reading the errors I installed it using python3 setup.py install. There were two setup.py files. One in the scikit-learn-master folder and sklearn folder so I ran python3 setup.py install at both these locations. They threw some warnings but no errors. I opened the python terminal in the scikit-learn-master folder and used import sklearn which returns the following -
Traceback (most recent call last):
File "/Users/shubhamgandhi/Desktop/scikit-learn-master/sklearn/__check_build/__init__.py", line 44, in <module>
from ._check_build import check_build # noqa
ModuleNotFoundError: No module named 'sklearn.__check_build._check_build'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shubhamgandhi/Desktop/scikit-learn-master/sklearn/__init__.py", line 128, in <module>
from . import __check_build
File "/Users/shubhamgandhi/Desktop/scikit-learn-master/sklearn/__check_build/__init__.py", line 46, in <module>
raise_build_error(e)
File "/Users/shubhamgandhi/Desktop/scikit-learn-master/sklearn/__check_build/__init__.py", line 41, in raise_build_error
%s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of /Users/shubhamgandhi/Desktop/scikit-learn-master/sklearn/__check_build:
__init__.py __pycache__ _check_build.c
_check_build.pyx setup.py setup.pyc
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
I am not sure how to proceed. Is there anything I am missing?
It appears the module has not been built correctly. And so it shows importError for check_build.
Before installing the module using pip, make sure you have installed all of the dependencies. On the README file, the mentioned packages are:
Python (>= 2.7 or >= 3.3)
NumPy (>= 1.8.2)
SciPy (>= 0.13.3)
For running the examples Matplotlib >= 1.1.1 is required.
If you are not planning on contributing to the project, but only using it, it is recommended that you download from https://pypi.python.org/pypi/scikit-learn instead of forking it.
View detailed instructions on how to install here.
After installing and building this way, if you still have issues, you can refer http://scikit-learn.org/stable/faq.html for FAQs.
I'm using cairo plot to draw charts with python. I followed the instruction as stated on the website to install Cairplot, http://linil.wordpress.com/2008/09/16/cairoplot-11/ :
sudo apt-get install bzr
bzr branch lp:cairoplot/1.1
The installation completes successfully.
I then try to import the modules in python:
>>> import CairoPlot Traceback (most recent call last): File "<stdin>",
line 1, in <module> ImportError: No
module named CairoPlot
>>> import cairo
>>>
Importing cairo is fine, but I can't figure out why I am not able to import CairoPlot.
bzr branch lp:cairoplot/1.1 creates a directory called 1.1 in your current working directory. Inside you'll find CairoPlot.py. Move CairoPlot.py into a directory which is listed in your PYTHONPATH, or edit your PYTHONPATH to include (the unfortunately named) 1.1.
Is the directory where CairoPlot is installed in your $PYTHONPATH? Do you need to run any setup scripts, like setuptools?
The repository appears to include a setup.py file, so you likely need to run setuptools to fully install the module.