shiv
shiv copied to clipboard
Can't get shiv to work with 3rd party libs
I've created the hello script and generated a zip fine. But when I want to add a 3rd party lib, it doesn't work.
I did this in main.py:
`def main(): print("Hello, world!")
if name == "main": main()`
Then this in setup.py:
`from setuptools import setup
setup( name="hello-world", version="0.0.1", description="Greet the world.", py_modules=["hello"], entry_points={ "console_scripts": ["hello=hello:main"], }, )`
Then ran python -m shiv -c hello -o hello .
The file generates and runs fine:
./hello Hello, world!
But can't find any documentation that says how to include a package like:
python -m pip install colorama
Then in main.py add:
`import colorama
def main(): print(colorama.Fore.RED + "Hello, world!")
`
When I build and run I get the error:
Traceback (most recent call last): File "./hello/_bootstrap/__init__.py", line 77, in import_string File "/Users/name/.shiv/hello_81294a9e40b439ea067c49f4da246174dd4ab5aa25867cfe8b3f3f2ddcb4fdc2/site-packages/hello.py", line 2, in <module> import colorama ModuleNotFoundError: No module named 'colorama'
So then I figured I had to include it in setup.py:
setup( name="hello-world", version="0.0.1", description="Greet the world.", py_modules=["hello", "colorama"], entry_points={ "console_scripts": ["hello=hello:main"], }, )
But when I build and run, I get the same error. How do I include 3rd party libs?
Yes, I'm a python noob and trying to find a workflow for generating self-contained scripts. Shiv seems perfect for what I'm looking to do, but I've been struggling to get this to work. I'm trying this on macos in a venv. I've checked my python version in the venv and it's 3.8.9, so it should be good (i.e. and that's why I didn't use python3 on the cli)
Hi @u84six,
In your setup.py
file add install_requires=["colorama==0.4.4"]
to your setuptools.setup
invocation.
You can read more about how to declare dependencies from a Python package here.
Another way would be to simply pass it to shiv
, like how you are already but add colorama
:
python -m shiv -c hello -o hello . colorama
Hope that helps!
Hi @u84six,
In your
setup.py
file addinstall_requires=["colorama==0.4.4"]
to yoursetuptools.setup
invocation.You can read more about how to declare dependencies from a Python package here.
Another way would be to simply pass it to
shiv
, like how you are already but addcolorama
:python -m shiv -c hello -o hello . colorama
Hope that helps!
Now when I run ./hello I see: bash: ./hello: C:\Program: bad interpreter: No such file or directory
I'm using git bash for Windows (I hate Windows cmd). I opened my pyvenv.cfg and home is pointing to the global python installation directory (home = C:\Program Files\Python310). I'm not sure why. Shouldn't it be pointing to the one in the venv?
When venv is activated, 'which python' and 'which pip' is pointing to the local one, which is to be expected.
Also, if I try executing it like 'python ./hello' I get the error: ModuleNotFoundError: No module named 'hello'