Using Pyphen with jython - python-3.x

I am trying to run a Python script from a Java class using jython 2.7.0 and I need to use pyphen as part of the script. The following line in my Python script causes the following error message.
from pyphen import Pyphen
ImportError: No module named pyphen
My question is: Does jython have the capability to use the pyphen module?
And if jython can use the pyphen module, how do get it so jython knows about pyphen?

Related

Python command in Terminal works perfectly, but through AppleScript it throws an error

I have a Python script that runs fine through Terminal, but from the moment I try to run the same script with AppleScript (do shell script), I get an error about Python modules that couldn't be found.
More specific:
The script I run refers to a previously installed module, beginning with:
from platform import mac_ver
from Cocoa import NSURL
from CoreFoundation import CFPreferencesAppSynchronize
from CoreFoundation import CFURLCreateWithString
from CoreFoundation import kCFAllocatorDefault
...
While running this in AppleScript, I get an error saying the Cocoa module couldn't be found. I put that line in comment just to test, after which an error about the CoreFoundation module appears. It seems as if the script can't connect with anything that is needed for proper execution.
What could cause this?
Thanks for any info on this!
AppleScript do shell script uses a default shell that has a stripped-down PATH variable. That will make it default to OSX's default Python 2.x install. The easiest solution is to use an explicit path to your install of Python 3.9 (likely something like /usr/bin/python3 or /usr/local/bin/python3).

Unable to get instance of seleniumLibrary in robotframework

I am using robot framework with python. I am trying to get seleniumLibrary instance in python file using following code
from robot.libraries.BuiltIn import BuiltIn
class PythonDemo(object):
def __init__(self):
self.myInstance = BuiltIn().get_library_instance('SeleniumLibrary')
When i try use self.myInstance to populate keywords, its not showing in .py file.
In .robot file, i can easily access robot and seleniumLibrary keywords. But unable to use seleniumLibrary instance in .python file
Below are configuration details-
Pycharm community edition 2020.3
robotframework 3.2.2,
robotframework-pythonlibcore 2.1.0,
robotframework-ride 1.7.4.2,
robotframework-seleniumlibrary 3.3.1,
selenium 4.1.0,
python 3.8.0,
plugin - intellibot#seleniumLibrary Patched.
is there any setting in Pycharm? or am i missing anything?
Could anybody please help me with this issue?
Thanks
Not Possible - you will get RobotNotRunning exception if you just try to acquire "instance" of a library via BuiltIn() if the python code you have is executed directly and not by adding Library YourPythonCodeLib to settings section of the "your_test_or_task.robot".

Importing a module that needs an exported variable

I have a custom module that needs an library through an environment variable to be set correctly, which I am using in a script.
When I export from commandline and run the script, it works fine:
export FOO_LIB=/path/to/lib
python3 myscript.py
However without that, the import foo in my script throws exception:
ImportError: dlopen(/path/to/site-packages/bar.so, 2): Library not loaded: bar.dylib
In my script I tried
os.environ['FOO_LIB'] = '/path/to/lib'
import FOO
I still get the same error.
Is there a way I can do this in the python script itself without having to use bash export at all?

python3 execute script without dependency

My python3 script currently requires pypdf2 for execution.
If I want to run it on another device I would have to install python3, pip and pypdf2.
Is there a way to include pypdf2 into my script so that I only need python itself to run my script?
EDIT:
The script runs on windows (10)
If you want to distribute your script you can do this using PyInstaller as a stand-alone application.
This is a python module that bundles the interpreter with all the required libraries.

Getting python2.7 path in django app for subprocess call

I am using linux. I am trying to run daemon from function in django views. I want to run shell command from a view in Djangp app. I am using python 2.7. Command needs python2.7 path.
My app will be like plug n play. So on system on which it is going to install may have python installed on different location. So I want to make python path dynamic.
Command will be
usr/bin/python2.7 filename.py --start
On my system path is usr/bin/python2.7.
I found follwing using os.
On python shell I tried following code & I get what I want
import os
getPyPath = os.popen('which python2.7', 'r')
pyPath = getPyPath.read()
pyPath.rstrip()
I got o/p as which is expected as below
usr/bin/python2.7
So now how to get this code is django app view function & run it so that I can get python path in a variable.
I found pythons subprocess module call using which we can run command through shell using shell=True.
So can I get above code running in django view function using subprocess call??
If not what is the other ways to get python path in variable in function django views.
Thanks in advance.
To view the full path to the current Python interpreter, use sys.executable
import sys
print(sys.executable)

Resources