solving paste.evalexception ImportError with plone.app.debugtoolbar? - debugging

i'm trying to include plone.app.debugtoolbar into my plone4.2 buildout, but running into the same "ImportError: No module named paste.evalexception" described near the end of Martin's announcement: http://plone.293351.n2.nabble.com/ANN-plone-app-debugtoolbar-td6988915.html. this made me think the dependency had been fixed but i'm still getting it?
File "/home/rik/Plone/buildout-cache/eggs/plone.app.debugtoolbar-1.0a2-py2.7.egg/plone/app/debugtoolbar/browser/interactive.py", line 10, in <module>
from paste.evalexception import evalcontext
zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/home/rik/Plone/zeocluster/parts/client1/etc/site.zcml", line 16.2-16.23
ZopeXMLConfigurationError: File "/home/rik/Plone/buildout-cache/eggs/Products.CMFPlone-4.2.0.1-py2.7.egg/Products/CMFPlone/configure.zcml", line 102.4-106.10
ZopeXMLConfigurationError: File "/home/rik/Plone/buildout-cache/eggs/plone.app.debugtoolbar-1.0a2-py2.7.egg/plone/app/debugtoolbar/configure.zcml", line 10.2-10.32
ZopeXMLConfigurationError: File "/home/rik/Plone/buildout-cache/eggs/plone.app.debugtoolbar-1.0a2-py2.7.egg/plone/app/debugtoolbar/browser/configure.zcml", line 113.4-120.10
ImportError: No module named paste.evalexception
does this require some patch, pinning of paster...?

Simply adding an explicit dependency on Paste to my buildout:
devtools =
...
Paste
plone.app.debugtoolbar
did the trick! i'm still not sure why this dependency isn't/can't be part of plone.app.debugtoolbar, but it does seem to be a totally intra-buildout issue and unrelated to the 'external' shell's python, as #Martijn and i pursued above.

You are missing the Paste egg; in some cases, this egg is nested inside a development egg within your buildout which confuses buildout and it won't install it.
The work-around is to install it manually:
python -m easy_install Paste

Related

Replacing inconvenient package name. Got error: replacement module without version must be directory path (rooted or starting with ./ or ../)

Problem
In go.mod file I wrote:
module github.com/Siiir/vector
go 1.17
require github.com/huandu/go-clone v1.3.2 // indirect
replace clone => github.com/huandu/go-clone[v1.3.2]
It says that I cannot do such a replacement.
I actually solved my problem with the name of imported package.
It is convenient & working without that dash. I found that I can use clone.something to refer to a function.
No need to type go-clone.something.
Anyway, assume that a package name is indeed crazy or inconvenient. How can I replace it?
What I've seen:
I've seen a sibling question:
go modules - replace does not work - replacement module without version must be directory path (rooted or starting with
What I tried:
Working with terminal:
go mod edit -replace=clone=github.com/huandu/go-clone
got: go: -replace=clone=github: unversioned new path must be local directory
manual editing:
Attempts like: replace clone => github.com/huandu/go-clone[v1.3.2]
got: replacement module without version must be directory path (rooted or starting with ./ or ../)
Anyway, assume that a package name is indeed crazy or inconvenient. How can I replace it?
You cannot.
And you should not. The import path is something you write just once in the import declaration and the package name can be changed on a per file level with import nicename "something.you.think/is-totally/inconvenient/and/unacceptable-to/your_taste" .

Loading pre-trained BERT model error - Error no file named ['pytorch_model.bin', 'tf_model.h5'] found

I think my problem here is due to transformer version mismatch... but I would like some help with this...
Previously I used the huggingface library to perform language model fine tuning. This takes a corpus, an existing BERT model, and fine tune that model using this corpus. My command was
python run_language_modelling.py --output_dir=lm_finetune --model_type=bert --model_name_or_path=bert-base-uncased --do_train --train_data_file=thread0_wdc20.txt --do_eval --eval_data_file=wiki.test.raw --mlm --save_total_limit=1 --save_steps=2 --line_by_line --num_train_epochs=2
I fine-tuned the models successfully, and this created a folder that contained the following files:
checkpoint-183236 config.json eval_results_lm.txt lm_finetune pytorch_model.bin special_tokens_map.json tokenizer_config.json training_args.bin vocab.txt
And I also successfully loaded this fine-tuned language model for downstream tasks.
The problem is that I don't remember the versions of the libraries I used to do all these - pytorch, transformers, tensorflow...
Recently, I am experimenting something that required me to re-install these libraries. Their versions are now:
tensorflow-gpu 2.2.0
transformers 3.0.2
pytorch 1.4.0
torchtext 0.5.0
And when I use this environment to reload those previously fine-tuned language models, I get this error:
File "/home/li1zz/.conda/envs/tensorflow-gpu/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/li1zz/.conda/envs/tensorflow-gpu/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/li1zz/wop_matching/src/exp/run_bert_standard.py", line 313, in <module>
bert_model = transformers.TFBertModel.from_pretrained(bert_model)
File "/home/li1zz/.conda/envs/tensorflow-gpu/lib/python3.6/site-packages/transformers/modeling_tf_utils.py", line 437, in from_pretrained
[WEIGHTS_NAME, TF2_WEIGHTS_NAME], pretrained_model_name_or_path
OSError: Error no file named ['pytorch_model.bin', 'tf_model.h5'] found in directory /home/li1zz/bert/lm_finetune_proddesc/lm_finetune_part00 or `from_pt` set to False
Obviously, the file that is missing now is
tf_model.h5
I don't understand how I had this error - the fine-tuned models worked for sure before. And the only thing I can think of is the version mismatch. I.e., I fine-tuned those models using a version of the libraries that are incompatible with the ones I am now using, as one file is missing.
Can anyone provide some insights to this? Am I using wrong versions of the libraries? How can I fix this without re-doing all the language model finetuning using this new environment again?
I have discovered that the solution should be adding 'from_pt=True' in the line that loads the model:
bert_model = transformers.TFBertModel.from_pretrained(bert_model, from_pt=True)
This is actually hinted in the error message. And it should be an added feature because I clearly remember that my previous code was working and it did not have this parameter.
The files you have mentioned above indicate that you have trained a PyTorch model (pytorch_model.bin), but in your own answer you try to load a TensorFlow model with:
bert_model = transformers.TFBertModel.from_pretrained(bert_model, from_pt=True)
As you have already figured out, you can create a TensorFlow model from a PyTorch state_dict by setting from_pt=True. But in case it does not matter for you if you use PyTorch or TensorFlow, you could initialize a PyTorch model right away with:
bert_model = transformers.BertModel.from_pretrained(bert_model)
I have not tried it, but I assume that this will be faster. The documentation also mentions that it is faster to convert the PyTorch state_dict with one of the provided conversion scripts and loading the model afterward as using from_pt=True.

sphinx autodoc creates blank page on readthedocs, but correctly includes module docstring locally

I'm getting different results from autodoc when I run sphinx locally (versions 1.6.6 or 2.0.1 on Anaconda Python 3.6.8 for Mac) than when I run it on readthedocs.org (according to their log it's Sphinx version 1.8.5, and probably Python 2.7 since it's launched with python rather than python3).
The difference is in the results from the following file, Shady.Text.rst, which contains no more than:
Shady.Text Sub-module
=====================
.. automodule:: Shady.Text
Now, this sub-module happens to contain only a module-level docstring and no member docstrings—that's as intended, so the corresponding html page should contain the module docstring and no more. And this is exactly what happens when I run make html locally. However the result at https://shady.readthedocs.io/en/latest/source/Shady.Text.html is content-free (header only, no module docstring).
FWIW my autodoc-related entries in conf.py are:
autoclass_content = 'both'
autodoc_member_order = 'groupwise'
What am I doing wrong?
Thanks #StevePiercy for drawing my attention to the crucial lines in the raw log file:
WARNING: autodoc: failed to import module u'Text' from module u'Shady'; the module executes module level statement and it might call sys.exit().
WARNING: autodoc: failed to import module u'Video' from module u'Shady'; the module executes module level statement and it might call sys.exit().
(I had searched the 9000-line log file for .Text, because Text on its creates too many hits, but it hadn't occurred to me to search it for 'Text' in quotes).
To me, the message is misleading: the problem is not that "the module executes module level statements" because that per se is allowed. I wasted some time after noting that some module-level statements seemed to be allowed in other sub-modules, and tried to bundle the offending module-level statements into a class decorator thinking maybe sphinx's mysterious module-level-statement-detector would miss them then...)
No, the problem is that not the fact that the module-level statements exist and might call sys.exit(), but the fact that they did indirectly call sys.exit() during sphinx's compilation procedure. This was a quirk of the way I handle missing dependencies, which should probably be re-thought, but I could work around it for now by avoiding my sys.exit() call when os.environ.get('READTHEDOCS') is truthy.

Django app in Eclipse won't run after upgrade to django 1.4

After upgrading to Django 1.4, I now get the following error message:
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named py
I read that it might have something to do with pydev 2.4 eg: here, so I upgraded pydev to the latest version, 2.5. I am using eclipse indigo.
I started to have a look at the run cnofiguration, and noticed that the django 1.3 egg was still being referenced. So I went to windows/preferences/pydev/interpreter-python, and the 1.3 egg was being referenced in the system PYTHON path.
To try and correct this, I removed the existing python interpreter, and re-added a new one. My python is run from venv, so I added this. An error comes up:
I don't think this is related, but I can see that /venv/lib has appears in the System PYTHONPATH list, whereas in Windows the folder is called /venv/Lib, so I added this as well. Still the new django egg hasn't been include, so I manually added this under the 'Libraries' window.
However, I'm still receiving the error message.
The app runs fine from the command line.
Figured this out after a few hours of trying different things.
I created a new Django project using the pydev 2.5 just to see what would happen, and I noticed that the 'django settings module' entry (see below) was appname.settings. Previously I had put 'settings.py'. I removed the entry entirely, which cleared up the first problem.
After this I was getting a 'module appname not found' error, so I tried putting an empty __init__.py file in the root of my app, which seemed to work.
In a virtualenv, this is usually the case where you forgot to add the /Lib from the base python install during the install process (so, when searching in the PYTHONPATH it's not finding things such as 'threading.py' or 'traceback.py', etc.
I solved this by adding the following to manage.py:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = '<django_app_folder>.settings'
os.environ['SERVER_NAME'] = '<name_of_server>'
<django_app_folder> is the name of the folder containing the settings.py file.
<name_of_server> needs to be there, but I didn't find that it matters what it's set to.
I had this problem. My project did not have a PyDev - Django property so the other solution here did not work. I think this is because I did not initially create it as a Django project. Instead, what worked was:
right click project > properties > PyDev PYTHONPATH > String substitution variables.
Add a variable named DJANGO_SETTINGS_MODULE Its value should be yourapp.settings (or edit it if it's already there)

Embedded Python loads module but does not load that module's internal import statements

At long last(!) I've compiled Boost::Python and have gotten my XCode project to import a local module. This module starts with the line from xml.dom import minidom, but when it executes, I'm given this error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "FeedStore.py", line 1, in <module>
from xml.dom import minidom
ImportError: No module named xml.dom
However, I know that I've installed the xml Python module -- when I open Python from my command prompt and type from xml.dom import minidom, everything goes smoothly. Moreover, when I import the module, it behaves as I would expect.
I suspected that there was something wrong with sys.path, so I compared the one I get from the prompt to the one that's being used in my embedded module. The only difference is that the embedded sys.path does not include ''. I've tried appending it, but that didn't change the behavior.
I also suspected that the embedded version was accessing a different version of Python than I was using from the prompt, but sys.prefix matched between both executions.
Here's the code that imports my module and runs it. It's pretty bare-bones at the moment (not even reference counting yet) because at this point I'd just like to make sure I'll be able to embed my module (I'm a total newbie C++ programmer).
Py_Initialize();
//PyRun_SimpleString("import sys");
//PyRun_SimpleString("sys.path.append('')"); //tried this to no avail!
PySys_SetPath("/Users/timoooo/Documents/Code/TestEmbed/"); //this allows me to import my local module
PyRun_SimpleString("import FeedStore as fs"); //here's where it whines about the lack of xml.dom
PyRun_SimpleString("store = fs.feedStore()");
PyRun_SimpleString("print store.next()");
Py_Finalize();
I'm probably misunderstanding something essential about boost::python. Can anyone help me out?
Despite having identical sys.path values, calling
PyRun_SimpleString("sys.path.append(\"<<path>>\")");
with the places I needed fixed the problem.

Resources