Python version, "2.7.2+", what does the plus mean? - python-2.7

I have a virtual environment that I installed some time ago. When I activate it and run python I'm told that the version number is
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
What does the plus after the version number mean?
And could that somehow explain why the function os.urandom is not defined, even when (according to the documentation) it has been there since version 2.4.
>>> from os import urandom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name urandom

From the Python FAQ:
You may also find version numbers with a “+” suffix, e.g. “2.2+”.
These are unreleased versions, built directly from the CPython
development repository. In practice, after a final minor release is
made, the version is incremented to the next minor version, which
becomes the “a0” version, e.g. “2.4a0”.
And for your second question, the inability to import urandom in a virtualenv is a known problem.
This answer to a similar question should be helpful.

Related

Pyomo Util Module Not Found

So I asked a question a month ago. I had a really nice answer to that question. I wanted to test if the answer works right now. But I am getting ModuleNotFoundError.
I did following before testing:
conda install -c conda-forge pyomo
conda install -c conda-forge pyomo.extras
I want to run this script in my code (copy/pasted from the other question):
from pyomo.util.infeasible import log_infeasible_constraints
...
SolverFactory('your_solver').solve(model)
...
log_infeasible_constraints(model)
Error I encounter:
N:\urbs>python runme.py
Traceback (most recent call last):
File "runme.py", line 9, in <module>
from pyomo.util.infeasible import log_infeasible_constraints
ModuleNotFoundError: No module named 'pyomo.util.infeasible'
How to install it then? I checked doc etc..., could not find a way.
Pyomo 5.5 (the latest released version as of 23 August 2018) does not yet have that feature. I had mistakenly assumed that it was included. You can either change your version of pyomo to track master, or more easily, you can simply take the function at https://github.com/Pyomo/pyomo/blob/master/pyomo/util/infeasible.py and place it in your own code (along with the associated required imports).

pip installer seems not to write in the PATH in a Python server

I tried to download Graphlab from Turi wit the following tutorial. I coded with their tools and tried to compute a Python script but it answered me an ImportError.
(gl-env)ubuntu#ip-172-hey-hey-hey:~/Eclipse-Stats$ source deactivate
discarding /home/ubuntu/anaconda2/envs/gl-env/bin from PATH
ubuntu#ip-172-hey-hey-hey:~/Eclipse-Stats$ unset PYTHONPATH
ubuntu#ip-172-hey-hey-hey:~/Eclipse-Stats$ python Main.py
2017-07-27 14:56:00.520425
/home/ubuntu/.local/lib/python2.7/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
Traceback (most recent call last):
File "Main.py", line 3, in <module>
import prediction
File "/home/ubuntu/Eclipse-Stats/prediction.py", line 1, in <module>
from graphlab.toolkits.recommender import ranking_factorization_recommender
ImportError: No module named graphlab.toolkits.recommender
Actually it cames often on the server when I tried to download with pip numpy, scipy, sklearn... Like we can see in the following conversation (in Spanish) between FJSevilla and the man of my team I'm working with.
Two things: (1) check the version of your Python console and see if it matches or is higher than the compatibility with the packages. If you look at the depreciation message and read it through, you would understand what is going on a little more. (2) be careful of what you are importing and how you import them because your formatting might also be a syntactic all error. One thing you could do is find the package, manually download, unzip, then run the setup.py.

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.

web2py is not starting with python 3.0/3.1

I am trying to run a web2py application. Using python2.7 it is running fine.
But I want to use python higher version. When I try with python3.0 or 3.1, am getting an error as
Traceback (most recent call last):
File "/var/www/vhosts/astrozon/web2py/web2py.py", line 18, in <module>
import gluon.widget
File "/var/www/vhosts/astrozon/web2py/gluon/__init__.py", line 15, in <module>
from globals import current
ImportError: No module named globals
I have checked, the module gobals is present in the same folder. and python2.7 is able to import that module but not for 3.0 or 3.1.
I would greatly appreciate any suggestions.
web2py is not compatible with Python 3, and there are no plans to make it so, as that would break its promise to maintain backward compatibility. There have been a couple of experimental attempts at Python 3 forks, but I do not believe they have been maintained. Work has started on a web3py (not the official name) that will be Python 3 compatible, but that is a completely new framework and still in the early stages of development (there is a plan to include a compatibility layer allowing web2py applications to run under it).

Os.statvfs issue on Python2.7

I have installed python 2.7 and trying to run below code which always gives error:
# !/usr/bin/python
import os, sys
stinfo = os.statvfs("C:\Tools")
And error comes as :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'statvfs'
Any clue to make it work?
I'm assuming from your example file path that you're using Windows.
The os.statvfs() call is not supported in Windows. An attempt to add support was made, but was rejected.
You might find this answer helpful for possible solutions.
Make sure you are running in python2.7
import sys
print(sys.version)
Also you should escape a backslash
EDIT: See Mikes answer, did not know this is not implemented for Windows. Using it is also not wise because it is deprecated since Python2.6 and has been removed in Python3