shoebot / shoebot

Easy vector graphics with Python
http://shoebot.net
GNU General Public License v3.0
128 stars 24 forks source link

Use shoebot in python without install #400

Closed jabiertxof closed 2 years ago

jabiertxof commented 3 years ago

Is there a way to use python import module without instaling shoebot? I try to work with minimun rquerinments:

In my try I be blocked by this:

    from .bot import Bot
  File ".../Development/shoe/shoebot/grammar/bot.py", line 69, in <module>
    SBOT_ROOT = resource_filename(Requirement.parse("shoebot"), "")
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1130, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 342, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 886, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 772, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'shoebot' distribution was not found and is required by the application
rlafuente commented 3 years ago

So, I tried to reproduce this but couldn't. Here's the steps I took (this presumes you've already run install_dependencies.sh, which from your error I presume you did)

  1. Create a new virtualenv (I use virtualenvwrapper, so mkvirtualenv clean-shoebot)
  2. Install the python dependencies with pip install pycairo pygobject pillow meta pubsub
  3. Run the example script from the module docs inside the base shoebot directory:
import shoebot
bot = shoebot.create_bot(outputfile="output.svg")
bot.size(400,400)
bot.rect(10,10,100,100)
bot.finish()

This creates the file as expected. Are you inside the base shoebot/ dir? Can you import shoebot without error?

Thanks for reporting this, I guess the module docs/troubleshooting might need an update since this is something that should just work.

jabiertxof commented 3 years ago

I usualy never run python scripts to install, download the required packages ans place along my code so I go to pipy page and downoad meta and pubsub and place along shoebot folder (maybe I have miss pycairo and pygobject I supose is systemwide on my system) test tommorow at work (at home has all shoebot instaled by mistake)

Also want to have SVG only output so comment in source code PILL calls.
Maybe in the future need PDF but dont want to install PILL/PILLOW on my server

rlafuente commented 3 years ago

Good, let us know how it went when you get to try it.

You make a good point about Pillow -- it should only be needed if image() is used. Maybe we can try to remove it from the initial imports and only make image() and friends depend on it.

jabiertxof commented 3 years ago

Ok tomorrow give a look

stuaxo commented 3 years ago

It looks like that may be an old version ?

I think downloading packages individually used to be the norm when I started using python, but it's a bit more unusual. Is it because you find there is more control, vs using pip to install things from pypi ?

jabiertxof commented 3 years ago

I want less packages limited to minimun on server and control myself. I got it. My issue become from bot.py SBOT_ROOT. if I change to current folder it works. I only need to comment 2 times PILL/OW I have a beauty SVG, thanks!

stuaxo commented 3 years ago

That's fair enough.

I tend to use virtualenv for this (well for all my projects), it's handy as you can make a new one to test something and delete it afterwards, or have one to try out something that needs different versions of things.

rlafuente commented 3 years ago

My issue become from bot.py SBOT_ROOT. if I change to current folder it works.

This is great! Can you share how you changed SBOT_ROOT?

We also made it so that Pillow is only needed if you use image() (https://github.com/shoebot/shoebot/pull/402) -- thanks for reporting this one.

jabiertxof commented 3 years ago

I put a fixed path into into bot.py SBOT_ROOT variable :( to try.

Maybe we can use file on bot.py to add relative path

jabiertxof commented 3 years ago

Great the Pillow fix!

jabiertxof commented 3 years ago

Great to know PNG dont need it! Is possible add PDF format from cairo?

jabiertxof commented 3 years ago

thanks stuaxo. Virtualenv is a good thing always to help safe installs.

jabiertxof commented 3 years ago

https://cairographics.org/manual/cairo-PDF-Surfaces.html

stuaxo commented 3 years ago

@jabiertxof my favourite way of using virtualenv is virtualenvwrapper.

One problem with plain virtualenv is that it's easy to end up with a lot of them in various places in the filesystem.

With virtualenvwrapper they all live under ~/.virtualenvs then I can create them, list them and remove them with mkvirtualenv, lsvirtualenv, rmvirtualenv.

Apologies, if you are already familiar :)

jabiertxof commented 3 years ago

I know but never use so no need to be sorry! Thanks so much for trying to help me. also not know vistualenvwrapper!

stuaxo commented 3 years ago

Cool, it's sometimes hard to get a balance between telling people something useful or going too far the other way and being patronising.

jabiertxof commented 3 years ago

Yes social can be dificult sometimes but have good try is a + to it. Thanks again!

stuaxo commented 3 years ago

Hi @jabiertxof does this need more support, or can I close this ? Virtualenv / virtualenvwrapper is probably the way to go if you want isolation from the system - running apps manually isn't a standard thing.

I'm happy to look at changing SBOT_ROOT if that can help though.

Cheers Stuart

jabiertxof commented 3 years ago

Yes you can close I hardcore in my systems

⁣Obtener TypeApp para Android ​

En 28 may. 2021 19:15, en 19:15, Stuart Axon @.***> escribió:

Hi @jabiertxof does this need more support, or can I close this ? Virtualenv / virtualenvwrapper is probably the way to go if you want isolation from the system - running apps manually isn't a standard thing.

I'm happy to look at changing SBOT_ROOT if that can help though.

Cheers Stuart

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/shoebot/shoebot/issues/400#issuecomment-850557856

stuaxo commented 3 years ago

Paste the change you made was first though. If it's something I can change that's straightforward I'll try and do it, but if it's something where I end up fighting pip it may have to stay as-is.