Scribusoid

Author Topic: Importing Python Modules in windows  (Read 125 times)

Michihalo

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Scribus User
Importing Python Modules in windows
« on: April 17, 2019, 11:46:45 am »
Hey all,

When i tried to import a module into scribus on windows, it always said that the module was not installed, even if Environment variables were setup and the module was correctly installed on python itself.

I therefore ran this inside the console in Scribus

Code: [Select]
import pip
pip.main(['install', '<moduleName>'])

This installs the package for all users for Scribus, after a restart of Scribus you can use it in the console or in your scripts.

I don't know if this is the best way to do it, but it works for me. Hope this helps someone

PS: pip has to be installed i suppose. For me that worked without any troubles

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1885
  • Karma: 26
    • the graphics lab
Re: Importing Python Modules in windows
« Reply #1 on: April 18, 2019, 10:36:35 am »
hoi michi

would you mind testing this?

https://github.com/aoloe/scribus-plugin-scripter-pybind11/issues/2

Quote
# doing execfile() on this file will alter the current interpreter's
# environment so you can import libraries in the virtualenv
activate_this_file = "/path/to/virtualenv/bin/activate_this.py"

execfile(activate_this_file, dict(__file__=activate_this_file))

if you're using "-m venv" you'll probably need to find the virtualenv's "activate_this.py"...

i've not tested it, but it looks like a solution for your problem... slightly better than running pip from inside of scribus (which, imo, looks like a wonderful hack to me!)

Gibbz

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 0
  • Scribus User
Re: Importing Python Modules in windows
« Reply #2 on: May 10, 2019, 06:24:54 am »
I need some help with this.
Im trying to use the YAML library with scribus.
Ive done
pip install pyyaml

But when trying to import yaml, I get errors. I found this thread. Pip install hack above didnt work for me on Windows.
Ive noticed scribus comes with its own copy of python in the directory. How can I install yaml in there?


Edit, extracted yaml folder from its source into scribus/python/lib/yaml/ and its working :)
« Last Edit: May 10, 2019, 06:33:21 am by Gibbz »

 

palmate