how to fix the errors for gensim on window 10? - python

import gensim
Warning (from warnings module): File "E:\Program
Files\Python\Python35-32\lib\site-packages\gensim\utils.py", line 1212
warnings.warn("detected Windows; aliasing chunkize to chunkize_serial") UserWarning: detected Windows; aliasing chunkize to
chunkize_serial
I installed genism by using pip and then I tried to import genism.
but, there are some troubles as above.
How can I fix these problems?

You've faced with the warning message. Library you are using alerting that it would change default behavior due to the Window's peculiarities.
After you acknowledged the message, you could suppress it by adding this to the head of your program:
import warnings
warnings.filterwarnings(
'ignore',
'detected Windows; aliasing chunkize to chunkize_serial',
)

Related

GIMP 2.10 Python - How to import custom module?

I recently updated to 2.10 GIMP from 2.8, and it seems that none of my plug-ins that imported custom (relative) *.py files work anymore. I dissected the code and it's not the contents of the "path_tools.py" file, it's just the act of trying to import a custom module (even if it's an empty file it still won't work). Without this line of code it shows up in GIMP just fine:
from path_tools import *
The plugin and path_tools.py are both in the same folder
\AppData\Roaming\GIMP\2.10\plug-ins
I tried using explicit relative by adding periods
from .path_tools import *
from ..path_tools import *
from ...path_tools import *
etc.
I tried turning the file into a plug-in by adding an empty GIMP effect at the bottom of the file, to see if GIMP is just ignoring my file somehow
def path_tools(img, drw):
return
register(
"python-fu-path-tools",
"Path Tools",
"",
[...]
And by opening GIMP in command prompt
"c:\program files\gimp 2\bin\gimp-2.10" --verbose --console-messages
It just gives me a bunch of this kind of message for every plugin that won't load:
Querying plug-in: 'C:\Users\ \AppData\Roaming\GIMP\2.10\plug-ins\path_tools.py'
c:\program files\gimp 2\bin\gimp-2.10: LibGimpBase-WARNING: gimp-2.10: gimp_wire_read(): error
but those seem like warnings, especially since there is this actual error for another plug-in that wont load, for similar reasons I'm guessing:
GIMP-Error: Unable to run plug-in "export-ALL.py"
Is it related to these warnings at the top?
Parsing 'c:\program files\gimp 2\lib\gimp\2.0\interpreters\pygimp.interp'
GIMP-Warning: Bad interpreter referenced in interpreter file c:\program files\gimp 2\lib\gimp\2.0\interpreters\pygimp.interp: python
GIMP-Warning: Bad binary format string in interpreter file c:\program files\gimp 2\lib\gimp\2.0\interpreters\pygimp.interp
I just don't know what's going on, or what to do. Is there a directory that I can put the file in that it will be visible to the plugins? Because it does work to import regular modules like 'sys', 'os'.
(Sorry if this is a really stupid question, I've only used Python for GIMP plugins.)
It seems that the Python interpreter embedded with Gimp 2.10 uses / as a path separator whereas Gimp 2.10 uses \ on Windows.
The issue is discussed here.
Creating a file named C:\Program Files\GIMP 2\32\lib\python2.7\sitecustomize.py with the following content seems to fix the issue.
import sys
class Issue1542:
def __del__ (self):
if len (sys.argv[0]):
from os.path import dirname
sys.path[0:0] = [dirname (sys.argv[0])]
sys.argv = Issue1542 ()
You can hack the running file's containing directory's path into the sys.path before importing the module:
import os
import sys
sys.path.append(os.path.dirname(__file__))
import path_tools

Python on Mac OS Pycharm gives framework error with "import matplotlib.pyplot as plt"

This question is similar to the ones here and here but none of the solutions there work perhaps because I´m using a different environment (PyCharm on Mac OS).
In a virtual environment with PyCharm running on 2.7.15, matplotlib installed without any complaints, and a one-line PyCharm python file with the following content...
import matplotlib.pyplot as plt
...the console outputs the following error when running this one-line file:
/Users/jbs/PycharmProjects/WakeUp/env/bin/python /Users/jbs/PycharmProjects/WakeUp/InputSound/WakeInputSound-and-plot-it-trial3.py
Traceback (most recent call last):
File "/Users/jbs/PycharmProjects/WakeUp/InputSound/WakeInputSound-and-plot-it-trial3.py", line 2, in <module>
import matplotlib.pyplot as plt
File "/Users/jbs/PycharmProjects/WakeUp/env/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/jbs/PycharmProjects/WakeUp/env/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/Users/jbs/PycharmProjects/WakeUp/env/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 17, in <module>
from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework.
Any help resolving this would be most welcomed. I´ve tried about a dozen things and none seems to work...
(import matplotlib alone does not give problems and this question may be related to this one but it´s clearly different...)
For details refer: what-is-a-backend. You need to set your backend. There are two types of backends: user interface backends (for use in pygtk, wxpython, tkinter, qt4, or macosx; also referred to as “interactive backends”) and hardcopy backends to make image files (PNG, SVG, PDF, PS; also referred to as “non-interactive backends”).
There are four ways to configure your backend. If they conflict each other, the method mentioned last in the following list will be used, e.g. calling use() will override the setting in your matplotlibrc.
The backend parameter in your matplotlibrc file (see Customizing matplotlib):
backend : WXAgg # use wxpython with antigrain (agg) rendering
Setting the MPLBACKEND environment variable, either for your current shell or for a single script:
> export MPLBACKEND="module://my_backend"
> python simple_plot.py
> MPLBACKEND="module://my_backend" python simple_plot.py
Setting this environment variable will override the backend parameter in any matplotlibrc, even if there is a matplotlibrc in your current working directory. Therefore setting MPLBACKEND globally, e.g. in your .bashrc or .profile, is discouraged as it might lead to counter-intuitive behavior.
To set the backend for a single script, you can alternatively use the -d command line argument:
> python script.py -dbackend
This method is deprecated as the -d argument might conflict with scripts which parse command line arguments (see issue #1986). You should use MPLBACKEND instead.
If your script depends on a specific backend you can use the use() function:
import matplotlib
matplotlib.use('PS') # generate postscript output by default
If you use the use() function, this must be done before importing matplotlib.pyplot. Calling use() after pyplot has been imported will have no effect. Using use() will require changes in your code if users want to use a different backend. Therefore, you should avoid explicitly calling use() unless absolutely necessary.
Note:Backend name specifications are not case-sensitive; e.g., ‘GTKAgg’ and ‘gtkagg’ are equivalent.

flake8 not reporting on lines that are too long

If I create a file test.py with the following poorly-formatted contents:
import re
long_string = "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
class Foo():
pass
and run flake8 on the file from the command-line like this:
$ flake8 --max-line-length=79 test.py
only two errors are reported:
test.py:1:1: F401 're' imported but unused
test.py:3:1: E302 expected 2 blank lines, found 0
The max-line-length violation on line two is not reported.
Completely by accident (I was testing if any of the command options would be respected), I found that if I add an ignore option like this:
$ flake8 --max-line-length=79 --ignore=E302 test.py
Then the line length violation is reported:
test.py:1:1: F401 're' imported but unused
test.py:2:80: E501 line too long (97 > 79 characters)
I am on Ubuntu 16.04 and my flake8 version info is:
2.5.4 (pep8: 1.7.0, mccabe: 0.2.1, pyflakes: 1.1.0) CPython 3.5.1+ on Linux
When I posted a related question on the Emacs Stack Exchange site (I thought the issue was with an Emacs package initially), one of the users there pointed out that flake8 2.5.4 requires a lower version of pyflakes. However, installing flake8 through apt or pip automatically installs that particular version of pyflakes as a dependency, and I have been unable to get an older version of pyflakes to see if that solves the problem (maybe that is another question altogether).
Am I doing something wrong here, or is this a bug?
E501 is being ignored somewhere. It's either in ~/.config/flake8 or in the local directory in tox.ini, setup.cfg, or .flake8. Somewhere in one of those files you will probably find something akin to:
[flake8]
ignore = E501
(You may see it among other error codes too.)
This is not a bug in Flake8, and is almost certainly something in your environment causing this. The reason you see E501 is because you override the config file setting by providing --ignore on the command line.

Remove Python UserWarning

I just finished installing my MySQLdb package for Python 2.6, and now when I import it using import MySQLdb, a user warning appear will appear
/usr/lib/python2.6/site-packages/setuptools-0.8-py2.6.egg/pkg_resources.py:1054:
UserWarning: /home/sgpromot/.python-eggs is writable by group/others and vulnerable
to attack when used with get_resource_filename. Consider a more secure location
(set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
warnings.warn(msg, UserWarning)
Is there a way how to get rid of this?
You can change ~/.python-eggs to not be writeable by group/everyone. I think this works:
chmod g-wx,o-wx ~/.python-eggs
You can suppress warnings using the -W ignore:
python -W ignore yourscript.py
If you want to supress warnings in your script (quote from docs):
If you are using code that you know will raise a warning, such as a deprecated function, but do not want to see the warning, then it is possible to suppress the warning using the catch_warnings context manager:
import warnings
def fxn():
warnings.warn("deprecated", DeprecationWarning)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fxn()
While within the context manager all warnings will simply be ignored. This allows you to use known-deprecated code without having to see the warning while not suppressing the warning for other code that might not be aware of its use of deprecated code. Note: this can only be guaranteed in a single-threaded application. If two or more threads use the catch_warnings context manager at the same time, the behavior is undefined.
If you just want to flat out ignore warnings, you can use filterwarnings:
import warnings
warnings.filterwarnings("ignore")

Why do I get "UserWarning: Module dap was already imported from None ..."

I have python-matplotlib and python-mpltoolkits.basemap installed from Ubuntu packages. Installing python-mpltoolkits.basemap also installs python-dap as a dependency.
When I import basemap, I get this warning:
>>> import mpl_toolkits.basemap
/usr/lib/pymodules/python2.7/mpl_toolkits/__init__.py:2: UserWarning: Module dap was
already imported from None, but /usr/lib/python2.7/dist-packages is being added to sys.path
__import__('pkg_resources').declare_namespace(__name__)
What does this mean?
EDIT 1:
>>> import sys
>>> print sys.modules['dap']
<module 'dap' (built-in)>
EDIT 2:
$ python -S
Python 2.7.3 (default, Sep 26 2012, 21:53:58)
[GCC 4.7.2] on linux2
>>> import sys
>>> print sys.modules['dap']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'dap'
EDIT 3: yes I seem to have sitecustomize.py:
$ cat /etc/python2.7/sitecustomize.py
# install the apport exception handler if available
try:
import apport_python_hook
except ImportError:
pass
else:
apport_python_hook.install()
EDIT 4: actually I can get the error by:
>>> import pkg_resources
__main__:1: UserWarning: Module dap was already imported from None, but /usr/lib/python2.7/dist-packages is being added to sys.path
so this has nothing to do with mpl_toolkits.basemap as such.
I can't really say that I'd understand the details, but apparently whenever the package python-dap is installed, then trying to import pkg_resources gives this warning. Here is some discussion.
Following advice from here (comment 29 at the end of the page), I added dap as the first line in file /usr/lib/python2.7/dist-packages/dap-2.2.6.7.egg-info/namespace_packages.txt and get no more warnings. Hope this does not break anything.
I recently had to track down a similar problem, and the actual meaning of the error message:
UserWarning: Module dap was already imported from None, but /usr/lib/python2.7/dist-packages is being added to sys.path
Appears to be "While extending the path for 'dap', found an egg-info directory that does not declare 'dap' to be a namespace package".
This suggests two things: python-dap is missing a "namespace_packages=['dap']" declaration in its own setup.py, and setuptools really should give a better error message in this case...
If you don't need the package, simply remove it, e.g. on an Ubuntu or Debian system apt-get remove --purge python-dap removed the package for me and that silenced the warning. It is easy to accidentally install packages that you don't need because of dependency recommendations when installing some packages.
When you try to remove it the packaging system will warn you if removal of the package (in this case python-dap, but other packages could cause this error to happen, too) would also force removal of other packages which depend on it. In my case there are no other packages that directly depended on python-dap and I wasn't using it for anything that I was aware of, so uninstalling it was simple, painless, and silenced the warning.
Other package installers (such as the non-OS packaging systems like pip or easy_install) might make it more difficult to remove the package; you may need to delete the package by hand, so I'd instead recommend the accepted answer as the way to silence the warning unless the apt-get remove method I recommended here works for you.

Categories

Resources