Does Behave (BDD) work with Python 3.4? - python-2.7

I am using Behave (BDD for Python) and have been trying to enable JUnit output without success. After troubleshooting, I realized that I am getting the following error message only when using Python 3.4:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 "/Users/myusername/Documents/Programming/Selenium Programming/GMail Project/GMailTests.py"
Traceback (most recent call last):
File "/Users/myusername/Documents/Programming/Selenium Programming/GMail Project/GMailTests.py", line 62, in <module>
config = Configuration()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/behave/configuration.py", line 481, in __init__
load_configuration(self.defaults, verbose=verbose)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/behave/configuration.py", line 394, in load_configuration
defaults.update(read_configuration(filename))
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/behave/configuration.py", line 348, in read_configuration
result[dest] = cfg.get('behave', dest, use_raw_value)
TypeError: get() takes 3 positional arguments but 4 were given
When I update my project to use Python 2.7 instead, everything works fine.
Here is an important note: this is only causing trouble when I enable the JUnit output in the behave.ini config file. If I take the two lines below out of the config, everything goes fine. Unfortunately, I need to enable JUnit output for my project:
[behave]
junit=true
junit_directory=./JunitReports
If you know of any way I could make this work with Python 3.4, I'd love to know about it. Thanks in advance.

Changing the first line in the
script: /usr/local/bin/behave
to: #!/usr/local/bin/python3 #you might want to run which python3
resolved the issue

Looks like I answered my own question in my last comment. I just wanted to close the thread and provide an official answer as of 8/13/2014: behave is not fully supported on Python3.4, and even though most of it works fine when installed using pip3 install behave, the JUnit output option does not function.
There is a known issue for it that has been documented here.

Use behave-1.2.5.
Many Python3/Unicode related problems were fixed in this release. The tests run just fine on the CI server with Python 3.4.

Related

Getting no module named _internals error while using Bloomberg API

I am currently using Python 2.7 and my OS is Windows 7. While attempting to use the Bloomberg API I am getting this error:
Traceback (most recent call last):
File "datagrab.py", line 1, in <module>
import blpapi, time, json
File "C:\Python27\lib\blpapi\__init__.py", line 5, in <module>
from .internals import CorrelationId
File "C:\Python27\lib\blpapi\internals.py", line 50, in <module>
_internals = swig_import_helper()
File "C:\Python27\lib\blpapi\internals.py", line 42, in swig_import_helper
import _internals
ImportError: No module named _internals
I have set my path variable to point to blpapi3_64.dll and also updated my bloomberg terminal. I have also moved the local blpapi API to a different directory but still the problem exists.
I am kind of new to this API in general. So can someone please guide me?
Thank you in advance!
From your question is sounds like maybe you have tried this, but just outlining one possible solution from the README in the Python Supported Release release available here.
Note that many Python installations add the current directory to the
module search path. If the Python interpreter is invoked from the
installer directory, such a configuration will attempt to use the
(incomplete) local blpapi directory as a module. If the above
import line fails with the message Import Error: No module named
_internals, move to a different directory before invoking python.
I know this question is a bit stale, but in case people end up here like me. Do you have the C++ version of blpapi? it is a requirement for the python api as mentioned here: https://www.bloomberg.com/professional/support/api-library/
so download the C++ zip installer, extract somewhere, and then add it as an environment variable so that the python api can find it:
Environment variable name: BLPAPI_ROOT
Value: C:\blp\blpapi_cpp_3.8.18.1 (THIS IS WHERE MINE IS INSTALLED, YOUR VALUE HERE MAY BE DIFFERENT)
Hope that helps!

Why pypy is not recognizing my python 2.7/3.4 modules and packages?

I am running my python codes using either python script.py or python3 script.py. (The first one is based on 2.7 and the second one based on 3.4). However, recently I am working on a code that is pretty demanding in terms of computational expense. I am not an expert in python in order to speed up my code (which uses alot of other routines all compatible with both versions of python 2.7 and 3.4). When the .hdf5 input file of my function inside the code is on the order of 1 Mbi, the code is running and producing the result even though slowly. But when the .hdf5 input file of the function is on the order of 1 Gbi, the code almost never proceeds to the end and I am ending up with a "MemoryError:"
Traceback (most recent call last):
File "myscript.py", line 29, in <module>
gizmo.analysis.Image.plot_image(part, 'gas', 'mass.hydrogen.neutral', 'histogram', [0,1],[0,1,2], distance_max, distance_bin_width_Gas, distance_bin_number, part_indices=part_indices, write_plot=write_plot, plot_directory=plot_directory, background_color=background_color, use_column_units=True)
File "/home/username/Desktop/Projects/PaperMaterials/DM_Dominated_Objects/NewFolder2/covering_fractions/Simulations/gizmo/gizmo_analysis.py", line 817, in plot_image
weights = part[spec_name].prop(weight_prop_name, part_indices)
File "/home/username/Desktop/Projects/PaperMaterials/DM_Dominated_Objects/NewFolder2/covering_fractions/Simulations/gizmo/gizmo_io.py", line 145, in prop
self.prop(property_name.replace('mass.', 'massfraction.'), indices))
File "/home/username/Desktop/Projects/PaperMaterials/DM_Dominated_Objects/NewFolder2/covering_fractions/Simulations/gizmo/gizmo_io.py", line 157, in prop
values = (1 - self.prop('massfraction', indices)[:, 0] -
File "/home/username/Desktop/Projects/PaperMaterials/DM_Dominated_Objects/NewFolder2/covering_fractions/Simulations/gizmo/gizmo_io.py", line 65, in prop
return self[property_name][indices]
MemoryError
After doing some search on this website, I noticed that I can run python codes using pypy for example to speed them up. Since I am using Fedora 21 (32 bit) OS which comes with a pypy 2.4 version in its repository, I was able to install this version of pypy successfully. However, when I try to run my code using the command line pypy myscript.py instead of the ones mentioned above, I am left with error message:
File "app_main.py", line 75, in run_toplevel File "myscript.py",
line 1, in
import numpy as np ImportError: No module named numpy
It seems that pypy does not recognize all the python modules and packages including this particular one.
What would be your best suggestion for me given the fact that I would like to stick with Fedora 21 Linux distribution such that all the python modules and packages be recognized by pypy resulting in faster codes?
I can post what myscript.py is but I am not sure if that would be helpful at all given the fact that I am using lots of other routines in it.
PyPy 2.4 is a rather outdated version which contains no support for numpy (even if you tried to install it separately).
In any case it is very unlikely that even a brand-new version of PyPy would reduce the memory usage of a numpy-heavy program.
If you're hitting MemoryError at the scale of ~1-3GB of data in a single process, on a 32-bit OS, then it seems clear to me that you need a 64-bit OS.

Pyinstaller-generated exe cannot run on another computer

My computer's OS is 64-bit win 10. Python 2.7, 32-bit.
My code is plot.py, simple as below:
import matplotlib.pyplot as plt
import FileDialog
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
When I execute pyinstaller -F plot.py, the generated
plot.exe works as expected on my current computer. However, I get an error if I try to run it on a different 32-bit Windows 7 computer:
Traceback (most recent call last):
File "site-packages\GUI_tempCtrl\plot.py", line 3, in <module>
File "lib\site-packages\matplotlib\pyplot.py", line 3147, in plot
File "lib\site-packages\matplotlib\pyplot.py", line 928, in gca
File "lib\site-packages\matplotlib\pyplot.py", line 578, in gcf
File "lib\site-packages\matplotlib\pyplot.py", line 527, in figure
File "lib\site-packages\matplotlib\backends\backend_tkagg.py", line 84, in new
_figure_manager
File "lib\site-packages\matplotlib\backends\backend_tkagg.py", line 92, in new
_figure_manager_given_figure
File "lib\lib-tk\Tkinter.py", line 1814, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
C:/Users/ADMINI~1/AppData/Local/Temp/lib/tcl8.5 C:/Users/Administrator/lib/t
cl8.5 C:/Users/lib/tcl8.5 C:/Users/Administrator/library C:/Users/library C:/Use
rs/tcl8.5.15/library C:/tcl8.5.15/library
This probably means that Tcl wasn't installed properly.
Failed to execute script plot
You can try downgrading pyinstaller to v3.1 and rebuilding your exe file on your first computer to solve this issue.
Alternatively, you can fix it on your second computer by setting the TCL_LIBRARY environment variable to C:\Python27\tcl\tcl8.5\ (or wherever tcl8.5 is located)
PyInstaller has a known issue with Tkinter applications on Windows 7 and Windows XP.
Since this issue has gone unfixed for two years, I've gone ahead and started a bounty. Until the issue is fixed, there are a few workarounds you can try:
Workaround 1 - Manually copy missing files
As mentioned in a related issue, you can manually copy the missing files from your local Python installation.
Find your local Python installation. (%LocalAppData%\Programs\Python)
Make a copy of the missing folder (...\Python36-32\tcl\<missing_folder>)
Move the copy to your application's tcl folder (...\dist\<app_name>\tcl\<missing_folder>)
Workaround 2 - Run with --onefile
Running PyInstaller in --onefile mode seems to avoid this issue.
However, note that running in single file mode will increase startup time.
Workaround 3 - Downgrade to PyInstaller 3.1.0
pip install pyinstaller==3.1.0
According to ugoertz, downgrading to PyInstaller 3.1.0 resolved the issue.
Downgrading to 3.1.0 (and also downgrading setuptools to 19.2 because of the problem described in #1941) fixed the issue for me.

psiTurk: AttributeError: 'Process' object has no attribute 'get_connections'

Before I begin, let me give the disclaimer that I'm very new at this sort of thing, that my explanation may not be too coherent, and I have no ability to separate what might and might not be important.
I'd like to run psiTurk. But because psiturk doesn't work on Windows, I'm using Openshift to run Python, with psiturk inside of that. I've gotten Openshift working using PuTTY, and have gotten as far as launching the psiTurk shell. But even when I enter the command to turn the server on, the server remains off with the following error message.
[psiTurk server:off mode:sdbx #HITs:0]$ server on
Experiment server launching...
Now serving on myurl.rhcloud.com
Traceback (most recent call last):
File "/var/lib/openshift/[my SSH]/python/virtenv/lib/python2.7/site-packages/cmd2.py", line 789, in onecmd_plus_hooks
stop = self.postcmd(stop, statement)
File "/var/lib/openshift/[my SSH]/python/virtenv/lib/python2.7/site-packages/psiturk/psiturk_shell.py", line 205, in postcmd
self.color_prompt()
File "/var/lib/openshift/[my SSH]/python/virtenv/lib/python2.7/site-packages/psiturk/psiturk_shell.py", line 571, in color_prompt
server_status = self.server.is_server_running()
File "/var/lib/openshift/[my SSH]/python/virtenv/lib/python2.7/site-packages/psiturk/experiment_server_controller.py", line 144, in is_server_running
psiturk_exp_ports = [process[0].laddr[1] for process in [psutil.Process(int(pid)).get_connections() for pid in output]]
AttributeError: 'Process' object has no attribute 'get_connections'
'Process' object has no attribute 'get_connections'
Any help would be much appreciated.
Seems like standard pip install psiturk installs a version of the psutil library that's not compatible with psiturk. What worked for me was installing directly from git:
pip install git+git://github.com/NYUCCL/psiTurk.git#master
See this PR for details: https://github.com/NYUCCL/psiTurk/pull/192
Also, it's best to make a virtualenv to avoid problems with already-installed packages.

Compiling node.js on Cygwin

I'm trying to build node.js on my Windows XP box (Yes, it IS painful, thanks.) using Cygwin following Ryans instructions here.
Sadly calling "./configure" from the node source directory barfs up this:
$ ./configure
/home/LWE/sources/node.js/wscript: error: Traceback (most recent call last):
File "/home/LWE/sources/node.js/tools/wafadmin/Utils.py", line 274, in load_module
exec(compile(code, file_path, 'exec'), module.__dict__)
File "/home/LWE/sources/node.js/wscript", line 12, in <module>
import js2c
File "/home/LWE/sources/node.js/tools/js2c.py", line 35, in <module>
import jsmin
File "/home/LWE/sources/node.js/tools/jsmin.py", line 1
../deps/v8/tools/jsmin.py
^
SyntaxError: invalid syntax
I'm absolutely not into Python so I'm having a hard time figuring this out. Am I missing some dependency or what?
I'd expect that there is some simple little configuration switch that I have to turn, to make this work. I just don't know where/what/why/...
I compiled node.js on my Mac before from the very same sources and that worked like a charm. And I also can't imagine that the build script from the node repository itself is broken.
PS: It's a totally fresh and up to date Cygwin installation with Python 2.6.5.
I also had a problem getting nodejs to compile using cygwin - also a Python issue. I eventually found a reference to having to rebase the cygwin DLL links to make everything work. Of course I couldn't find my original source for help. But I remembered enough to find similar help.
So from http://avalanche123.tumblr.com/post/855374337/nodejs-mongodb-tinyurl
I remembered that you can stop all cygwin processes, run ash (a minimal shell) that is typically found at C:\cygwin\bin\ash.exe and then, in this shell, run "/usr/bin/rebaseall"
Once I had run the rebaseall command I could, using the normal cygwin shell, successfully run the ./configure script for the nodejs source and proceed to "make" and "make install" nodejs.
This is old, but for anyone referencing this page: jsmin.py is a symbolic link. If you are using Git from msysGit in Cygwin, symbolic links will not be created properly. The Git client that comes with Cygwin deals with these pretty decently most of the time, however every now and then it barfs. If you bring up jsmin.py in an editor, you will see it actually contains the path to the file it is supposed to be linking to. To fix this and move on to compiling:
# from the node.js source directory, run:
% cd tools
% ln -fs `cat jsmin.py`
This will recreate the symlink pointing to the proper location. From here, re-run ./configure and you are all set.
A full set of build instructions is available at Github.
I had no problems using Ryan's current instructions -- until I tried install ing NPM as well, and then I got no output. If you are using cygwin and installing node.js, be sure to use the "works" tag when you git the file, instead of a specific version number. Otherwise, no output/non working npm.
Now to figure out getting mongo setup properly...