0

Inexperienced in programming.

Svgwrite scripts only work in IDLE for me. Let's say you have this:

import svgwrite
svg_document = svgwrite.Drawing(filename = 'new.svg', size = (2400, 2400))
print(svg_document.tostring())
svg_document.save()

What would you need to add to make it run normally?

Thanks for any help!

  • 1
    So what happens when you run it outside of IDLE? – smheidrich Dec 31 '21 at 10:06
  • The svg file isn't saved. I can only create the svg file by running the script in IDLE. – Dog of Thunder Dec 31 '21 at 10:34
  • 1
    Strange, it works just fine for me. If it doesn't save it, it should normally at least give you an error message telling you what went wrong. Does it really just exit without saying anything if you run it from within a terminal? And for future reference: No matter what the answer is, information like that should always be part of the original question. "It doesn't work" is the least useful phrase, it should always be something like: It prints this error, it quits without saying anything, it freezes, it makes my PC explode, ... – smheidrich Dec 31 '21 at 11:06
  • Thank you! I don't get any error messages when running it by double clicking the .py file. The command prompt just flashes by, and no svg file generates. I just tried running it by opening the command prompt, going to the folder and typing "python test.py", and then it works (it creates the svg file), but I would prefer just being able to run the .py file normally. – Dog of Thunder Dec 31 '21 at 11:42
  • Whether it works with double clicking or not depends on how your operating system or file manager is configured. Some ideas can be found in other questions, e.g. [here for Windows](https://stackoverflow.com/questions/41639740/running-python-file-by-double-click), while on Linux, any reasonable file manager should be able to execute it after you made it executable via `chmod +x your_script.py` and put a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)#Examples) into its first line. Mac OS will be similar to Linux. – smheidrich Dec 31 '21 at 12:17
  • I actually take that back regarding Linux, many graphical file managers won't allow you to execute it even if it's executable... I guess another option would be to write a shell script (batch script on Windows) that executes it and put it into the same folder. – smheidrich Dec 31 '21 at 12:44

1 Answers1

0

Is SVGWrite an imported or system library? If it's an imported lib, you need to compile the code so it works. Use https://pypi.org/project/auto-py-to-exe/ programm. If it's a system lib, i have no idea.

Python User
  • 17
  • 1
  • 8
  • I guess it's an imported library. Here it is: https://pypi.org/project/svgwrite/ But I've used other imported libraries without encountering this problem. – Dog of Thunder Dec 31 '21 at 10:32