Unable to run a octave function using oct2py through the web server - python

I am using oct2py to call a octave function in my python code. The file is saved as .py file in the htdocs folder.
#!/usr/bin/python
import cgi
import oct2py
from oct2py import octave
print('Content-type:text/html\r\n\r\n')
print('<!DOCTYPE html>')
firnum='23'
secnum='33'
octave.addpath('/Applications/XAMPP/xamppfiles/htdocs/mypython/Octavemfiles/')
firnum=int(firnum)
secnum=int(secnum)
answer=octave.mymultfunct(firnum,secnum)
print(answer)
The code works well when executing from the terminal and gives the answer. But when I call it through the web, the oct2py gives an error stating
OSError: Octave Executable not found, please add to path or set"OCTAVE_EXECUTABLE" environment.
Please suggest a way out so I can call the function from octave. The octave function is just multiplying the numbers.

In Linux distribution:
command : sudo pip install oct2py
Error:
import oct2py
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/oct2py/init.py", line 38, in
octave = Oct2Py()
File "/usr/local/lib/python2.7/dist-packages/oct2py/core.py", line 73, in init
self.restart()
File "/usr/local/lib/python2.7/dist-packages/oct2py/core.py", line 508, in restart
logger=self.logger)
File "/usr/local/lib/python2.7/dist-packages/octave_kernel/kernel.py", line 157, in init
self.executable = self._get_executable()
File "/usr/local/lib/python2.7/dist-packages/octave_kernel/kernel.py", line 432, in _get_executable
raise OSError(msg)
OSError: Octave Executable not found, please add to path or set"OCTAVE_EXECUTABLE" environment variable
Solution
Please install octave using :
command : sudo apt-get install octave
ubuntu#host:~$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import oct2py

Related

Properly using Anaconda's Python as the PATH's "python"

I've noticed that while I can point my environment variables to Anaconda's Python interpreter, I don't get a fully working Python environment when I execute python in the command prompt. Python will still launch, but many of its packages are "broken."
PROBLEM:
Anaconda's Python interpreter does launch when called from command prompt, but it isn't able to import some of its packages (numpy being one of them used in this example).
EXAMPLE(WINDOWS CMD):
> where python
C:\Anaconda3\python.exe
Great, python calls the right interpreter. Let's go in there and import numpy!
> python
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
This is weird. Let's try launching "Anaconda Prompt", which appears to just be an activated Anaconda environment.
>python
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
Everything works fine this way.
SUMMARY:
I'm expecting Anaconda's Python interpreter to launch from the command prompt and behave just the way it would if launched from within the Anaconda Prompt (which appears to just be a command prompt with an activated Anaconda environment).
What can I do to be able to get a fully working Anaconda Python interpreter by just launching python from the Window's command prompt? Maybe what I'm really asking is, what do I need to change in my environment variables to ensure that the Anaconda environment is activated when I call on python from the command prompt?
Activating a conda environment can also change the PATH. I suggest you compare PATH before and after activating the environment.

jenkins python module import error

I have installed jenkins module in the VM but still not able import the module and use.
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import jenkins
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/jenkins.py", line 9, in <module>
lookup3 = cdll.LoadLibrary(os.path.join(get_python_lib(), "lookup3.so"))
File "/usr/lib64/python2.7/ctypes/__init__.py", line 438, in LoadLibrary
return self._dlltype(name)
File "/usr/lib64/python2.7/ctypes/__init__.py", line 360, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /usr/lib/python2.7/site-packages/lookup3.so: cannot open shared object file: No such file or directory
Have you installed jenkins by this command?
pip install jenkins
if yes you should try to install it with
pip install python-jenkins
Ref: Bug
This is already answered by Daniel Salinas (imsplitbit) on lunchpad at
bug in jenkins lib
Close this bug, it appears pip was installing jenkins 1.0.2 not python-jenkins 0.2 which is actually used. These two modules use the same module namespace so it may be valuable to change that some how or even just add python-jenkins to the pip-requires so that this isn't an issue to begin with.
I just met it. That's how it was solved
$ pip uninstall jenkins
Uninstalling jenkins-1.0.2:
/usr/local/lib64/python3.6/site-packages/__pycache__/jenkins.cpython-36.pyc
/usr/local/lib64/python3.6/site-packages/jenkins-1.0.2-py3.6.egg-info
/usr/local/lib64/python3.6/site-packages/jenkins.py
/usr/local/lib64/python3.6/site-packages/lookup3.cpython-36m-x86_64-linux-gnu.so
Proceed (y/n)?
here is a file: lookup3.cpython-36m-x86_64-linux-gnu.so, soft connection to the corresponding position is OK
sudo ln -s /usr/local/lib64/python3.6/site-packages/lookup3.cpython-36m-x86_64-linux-gnu.so /usr/lib/python3.6/site-packages/lookup3.so

Error with pattern while running example pattern.web.HTTP403Forbidden

I am working with Debian. I have installed Anaconda, then I created a virtual environment with Python2.7, and finally according with Pattern Anaconda Cloud I installed pattern by typing conda install -c asmeurer pattern
When I try to run the first example from here Pattern Clips I have the followinf error:
Python 2.7.14 |Anaconda custom (64-bit)| (default, Dec 7 2017, 17:05:42)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pattern.web import Twitter, plaintext
>>> twitter = Twitter(language='en')
>>> for tweet in twitter.search('"more important than"', cached=False):
... print plaintext(tweet.text)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/anaconda3/envs/venv27/lib/python2.7/site-packages/pattern/web/__init__.py", line 1471, in search
data = url.download(cached=cached, **kwargs)
File "/home/user/anaconda3/envs/venv27/lib/python2.7/site-packages/pattern/web/__init__.py", line 420, in download
data = self.open(timeout, proxy, user_agent, referrer, authentication).read()
File "/home/user/anaconda3/envs/venv27/lib/python2.7/site-packages/pattern/web/__init__.py", line 381, in open
if e.code == 403: raise HTTP403Forbidden(src=e)
pattern.web.HTTP403Forbidden
>>>
Any idea what is happening ? Thank you in advance
I solve the problem by installing Pattern directly from github. In order to do so I had to remove the Pattern version I had already installed in my virtual environment by conda remove pattern and then pip install git+git://github.com/clips/pattern

python import from subprocess fails

I have been working on some makefiles which call some python scripts to perform various tasks. Up to now, I had always been makeing on a machine with Ubuntu 16.04 (64 bits) installed. Today, I have tried building on my old 32 bits machine with Lubuntu 16.04 using the same makefile and it fails when calling the Python script.
At first, I thought that my Python version was not new enough, but I also have Python 3.5 installed and I changed the line to python3 in the makefile and it still fails:
python3 /home/morane/Documents/Programming/ConnectX/cxPythonTools/RunUnitTests.py -t /home/morane/bin/tests/unit/cxUnitTests.out -l /home/morane/bin/tests/unit/log/unitTests.log
Traceback (most recent call last):
File "/home/morane/RunUnitTests.py", line 41, in <module>
from subprocess import CREATE_NEW_CONSOLE
ImportError: cannot import name 'CREATE_NEW_CONSOLE'
Makefile:51: recipe for target 'unittests' failed
make: *** [cxbaseunit] Error
To test, I have tried to repeat the error directly in the Python shell:
Python 3.5.2+ (default, Sep 22 2016, 12:18:14)
[GCC 6.2.0 20160927] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> from subprocess import CREATE_NEW_CONSOLE
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'CREATE_NEW_CONSOLE'
and it still fails. Does anyone know whats going on?
Regards
It appears that you're running in Linux. The CREATE_NEW_CONSOLE constant is only available on Windows.
https://docs.python.org/3/library/subprocess.html#subprocess.CREATE_NEW_CONSOLE
Specifically the header of section 17.5.4:
The STARTUPINFO class and following constants are only available on Windows.

keep getting 'ImportError: No module named pygtk' when I try to run Gaphor on windows

I have installed pygtk-all-in-one-2.24.0.win32-py2.7.msi on windows, and installed gaphor by easy_install. When I try to run gaphor, I receive an import error.
PS C:\Python27\Scripts> .\gaphor.exe
Traceback (most recent call last):
File "C:\Python27\Scripts\gaphor-script.py", line 9, in <module>
load_entry_point('gaphor==0.17.2', 'console_scripts', 'gaphor')()
File "build\bdist.win32\egg\pkg_resources\__init__.py", line 521, in load_entry_point
File "build\bdist.win32\egg\pkg_resources\__init__.py", line 2632, in load_entry_point
File "build\bdist.win32\egg\pkg_resources\__init__.py", line 2312, in load
File "build\bdist.win32\egg\pkg_resources\__init__.py", line 2318, in resolve
File "C:\Python27\lib\site-packages\gaphor-0.17.2-py2.7.egg\gaphor\__init__.py", line 13, in <module>
import pygtk
ImportError: No module named pygtk
Any suggestions would be appreciated!
Did you actually install pygtk? I suspect easy-install should have pulled it in automatically. Did you see any errors during the install? pygtk also requieres installing gtk+.
Do a simple test - start Python in a console (ipython?), and type:
$ python
Python 2.7.6 (default, May 6 2014, 10:57:58)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygtk
>>> import gtk
>>>
There should be no error messages.
You can also search the disk for pygtk.py (with the file manager) and for a directory gtk-2.0 or gtk-3.0.

Categories

Resources