Install Python library without pip

Hello,

I’m new to Python, so please bare with me. I would like to use python-docx within Dynamo to be able (or try) to write to a Word document.
I went on the website for it and it explains how to install it using pip install but I don’t know how that works in IronPython through Dynamo or if it’s possible to use in Dynamo.
I’ve installed python-docx and lxml (a dependency) in a local folder but I don’t know how to access it.

So far I’ve tried this code but it can’t seem to get the library.

import clr
import sys
sys.path.append(r’[local path where python-docx is installed]')

Is there something I’m missing when it comes to Python packages? Does it need to be put in a specific spot?

Any help is appreciated!
Thanks!

Lynn

You can run external commands like scripts or executables from Dynamo. You can parse your data from Revit to Dynamo and then run a Python script from outside Revit and Dynamo. You can run Python with every library you need and both Python 2.x and 3.x
Take a look at this.

A Python script from inside Dynamo can run any arbitrary external command. You can run any shell script or executable. There’s no problem in installing stand alone Python 3.x or whatever version docx library needs and run external Python script within that environment.

To wrap up.

  1. Install stand alone Python.
  2. Install all required libraries.
  3. Create a .py script on your computer.
  4. Call your script from Dynamo
  • I don’t know if OP works alone or in corporate environment. His problem is solvable but not sustainable.
2 Likes

Yes, it seems this package is supported with IronPython 2.7.3. I made sure of that.
The thing is I have the package downloaded and unzipped, but how do I use the setup.py to install the package and get the init.py file?
I probably should’ve included that in the original post.
Also, I’m in an office and would like to put it in a shared drive location that other people could access. Does it have to go C:\Program Files (x86)\IronPython 2.7\Lib?
Thanks so much for the help!

Okay I see what you mean then. That’s convenient!
I guess it’s the package download that’s confusing me. After unzipping the package, it gave me a folder with the name of the package and setup.py, but I don’t know if that’s the actual package.
Do I run the setup.py somehow or place that in that folder?
How do I run that? Is that done through IronPython? Does that make sense?

Okay that’s what I needed. I didn’t realize I’d have to install Python, I figured I could go through IronPython but this sounds like a more straight-forward route. I’ll give it a try. Thank you so much! :smiley:

It’s just a proof of concept.

This is Dynamo graph
Workspace

This is Python code in Dynamo:

import clr
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import os
arg = IN[0]
os.system('python z:\external_script.py ' + arg)

You can also use subprocess for more control.

And this is external_script.py:

import sys
print(sys.version)
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))
input('Press Enter to continue...')

This is the outcome:

Console

3 Likes

You can also use subprocess which more flexible.
This code is from my first link.

from System.Diagnostics import Process
path = r"C:\somepath"
myfile = "somefile.docx"
command = "%s\\%s"% (path,myfile)

proc = Process()
proc.StartInfo.FileName = command
proc.Start()
proc.WaitForExit()

It’s not optimal but it gets work done.

And that’s the reason they stick with 2.7

Fairly certain that you could also call on the MS word API directly via Python - no add ins required, just need word installed.

I believe that this is hkw the bumblebee package accesses MS Excel.

Hi @jacob.small,
I just tried doing that just now and made a separate forum post about it. Trying to get that to work as well. Replace Word text using Interop