Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get shiv to work with 3rd party libs #195

Open
u84six opened this issue Oct 20, 2021 · 2 comments
Open

Can't get shiv to work with 3rd party libs #195

u84six opened this issue Oct 20, 2021 · 2 comments

Comments

@u84six
Copy link

u84six commented Oct 20, 2021

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)

@lorencarvalho
Copy link
Contributor

lorencarvalho commented Oct 20, 2021

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!

@u84six
Copy link
Author

u84six commented Oct 20, 2021

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!

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants