FedL - raise ValueError, "dataset must be 'testing' or 'training'" - python

Currently I'm working on implementing code in "Differentially Private Federated Learning: A Client Level Perspective" where the GitHub link is LINK.
However, I follow the instruction but got an error which is
Traceback (most recent call last):
File "sample.py", line 5, in <module>
from MNIST_reader import Data
File "/content/drive/MyDrive/Colab_Notebooks/machine-learning-diff-private-federated-learning-main/MNIST_reader.py", line 20
raise ValueError, "dataset must be 'testing' or 'training'"
SyntaxError: invalid syntax
I just run bash RUNME.sh and follow the instruction but still get an error!
!python sample.py —-m 100, sigma 1
You're welcome if you want to check the full code here.
Thanks a lot!!

Error SyntaxError: invalid syntax for line
raise ValueError, "dataset must be 'testing' or 'training'"
may suggest that code was created for Python 2 but you run Python 3.
You may have edit file MNIST_read.py and use () instead of , in line
raise ValueError("dataset must be 'testing' or 'training'")
BTW:
Some files on GitHub are 5 years old so it could be created for Python 2.
So you may excpect that code may have other problems with Python 3
Requirements shows Tensorflow 1.4.1 and it may have problem to run with your Tensorflow 2.8.4 because they change some elements.
Maybe it will be simpler to run it with Python 2
EDIT:
In GitHub in Insight / Network you can see all forks of this repo and fork created by rosdyana has last commit with title Fix code for python3.5 and maybe you should use this version.
But this version still may need to use Tensorflow 1.4.1 which may need older Python 3.5 or 3.6. I don't know if it works with the newest versions of Python.

Related

Running an Nsight Systems report python script independently

I've tweaked a copy of one of the Nsight Systems report scripts (gpukernsum), and I now want to run it myself. So, I write:
./gpukernsum.py report.sqlite
This doesn't work; I get:
ERROR: Script 'gpukernsum.py' encountered an internal error.
$ ./gpukernsum.py report.sqlite
File "./gpukernsum.py", line 40
"""
^
SyntaxError: invalid syntax
I know this is because f"""whatever""" is Python-3 syntax, so I change the script's hash-bang line from:
#!/usr/bin/env python
to:
#!/usr/bin/env python3
and now I get:
$ ./gpukernsum.py report.sqlite
Traceback (most recent call last):
File "/path/to/./gpukernsum.py", line 7, in <module>
import nsysstats
ModuleNotFoundError: No module named 'nsysstats'
So I added the relevant directory to the lookup path:
export PYTHONPATH="$PYTHONPATH:/opt/nvidia/nsight-systems/2022.1.1/host-linux-x64/python/lib"
and now I get:
$ ./gpukernsum.py report.sqlite
near "WITH": syntax error
... and I'm stuck. The relevant area of the code is:
and not a percentage of the application wall or CPU execution time.
"""
query_stub = """
WITH
summary AS (
SELECT
coalesce({NAME_COL_NAME}, demangledName) AS nameId,
i.e. the "WITH" is part of a string literal which is an SQL query. So, what's the problem? Is Python complaining? Is sqlite complaining?
Note:
Nsight Systems 2022.1.1
CentOS 7
I'm using the original gpukernsum.py code - I have not made any changes to it (other than as described above).
My system has Python 3.9.1 for python3.
A workaround answer:
Nsight Systems bundles its own version of Python, with lib and bin directories.
If you run your script with this specific version, having set PYTHONPATH as described in your question - then the script will work. It's what Nsight itself does, after all.

Cryptic Django CMS install error - what might be causing this error?

(env) Name-MacBook-Pro-2:site_cms name$ djangocms -f -p . site_cms
Creating the project
Please wait while I install dependencies
If I am stuck for a long time, please check for connectivity / PyPi issues
Dependencies installed
Creating the project
The installation has failed.
*****************************************************************
Check documentation at https://djangocms-installer.readthedocs.io
*****************************************************************
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/bin/djangocms", line 11, in <module>
sys.exit(execute())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/djangocms_installer/main.py", line 44, in execute
django.setup_database(config_data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/djangocms_installer/django/__init__.py", line 407, in setup_database
command, env=env, stderr=subprocess.STDOUT
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 376, in check_output
**kwargs).stdout
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 468, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7', '-W', 'ignore', 'manage.py', 'migrate']' returned non-zero exit status 1.
I am following the instructions on this page:
http://docs.django-cms.org/en/develop/introduction/01-install.html
However I am unsure why it is not installing.
Is there anyway to get more verbose data on the error? I'm trying to google each of these lines and nothing is consistent with the issue I am having.
Could it be due to Python version?
This is on OSX - High Sierra. Do I possibly need to do something to let Django CMS connect to my database?
In case anyone else runs into this issue, or if the OP never solved it, I encountered the same issue tonight and it looks like python 3.7 is indeed the culprit.
djangocms (currently) only supports up to Django 1.11, which does not appear to support python 3.7. Django 1.11 release notes
What tipped me off was re-running the install with the --verbose option and seeing this line:
'%s=%s' % (k, v) for k, v in params.items(),
^
SyntaxError: Generator expression must be parenthesized
A quick google search appeared to confirm that this is an issue with python3.7/Django 1.11 a la stack overflow.
According to the djangocms roadmap, Divio is leading development on the next major release which will include Django 2.0 (and thus python3.7, presumably) support.
In the meantime, you'll probably have to stick with python3.6, since djangocms' docs claim support for 3.6, even though the tutorial only lists up to python3.4.
Good luck!

PyDev 5.9.2 runtime error in Eclipse Oxygen 4.7.0

I'm using PyDev installed as an Eclipse extension (through the update site) on Windows 7 and WinPython 3.6.0.1. I can run code just fine even though the syntax checker is broken, i.e., marks as error "Undefined variable: print" lines as simple as
print("hello")
I think the issue is connected with this error I get in the error log as soon as I start Eclipse:
Error creating python process - exited before creating sockets - exitValue = (1).
This is the Exception stack trace
java.lang.RuntimeException: Error creating python process - exited before creating sockets - exitValue = (1).
ProcessInfo:
- Executed: C:\tools\winpython\3.6.0.1\python-3.6.0.amd64\python.exe -u C:\Portables\Eclipse\plugins\org.python.pydev_5.9.2.201708151115\pysrc\pycompletionserver.py 55270
- Environment:
ALLUSERSPROFILE=C:\ProgramData
[... list of all the environment variables ...]
- Working Dir:
C:\Portables\Eclipse\plugins\org.python.pydev_5.9.2.201708151115\pysrc
- OS:
Windows 7
- Std output:
- Err output:
Traceback (most recent call last):
File "C:\Portables\Eclipse\plugins\org.python.pydev_5.9.2.201708151115\pysrc\pycompletionserver.py", line 13, in <module>
from _pydevd_bundle.pydevd_constants import IS_JYTHON
ModuleNotFoundError: No module named '_pydevd_bundle'
at org.python.pydev.core.log.Log.log(Log.java:54)
at org.python.pydev.editor.codecompletion.shell.AbstractShell.startIt(AbstractShell.java:290)
at org.python.pydev.editor.codecompletion.shell.ShellsContainer.getServerShell(ShellsContainer.java:232)
at org.python.pydev.editor.codecompletion.shell.ShellsContainer.getServerShell(ShellsContainer.java:165)
at org.python.pydev.editor.codecompletion.shell.AbstractShell.getServerShell(AbstractShell.java:222)
at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.createTokensFromServer(CompiledModule.java:372)
at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.<init>(CompiledModule.java:176)
at org.python.pydev.editor.codecompletion.revisited.SystemModulesManager.getBuiltinModule(SystemModulesManager.java:332)
at org.python.pydev.editor.codecompletion.revisited.SystemModulesManager.getBuiltinModule(SystemModulesManager.java:1)
at org.python.pydev.ui.interpreters.AbstractInterpreterManager.getBuiltinMod(AbstractInterpreterManager.java:146)
at org.python.pydev.ui.interpreters.AbstractInterpreterManager.getBuiltinCompletions(AbstractInterpreterManager.java:118)
at org.python.pydev.plugin.nature.PythonNature.getBuiltinCompletions(PythonNature.java:1126)
at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getBuiltinComps(AbstractASTManager.java:1801)
at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getBuiltinCompletions(AbstractASTManager.java:1787)
at com.python.pydev.analysis.scopeanalysis.AbstractScopeAnalyzerVisitor.<init>(AbstractScopeAnalyzerVisitor.java:151)
at com.python.pydev.analysis.visitors.OccurrencesVisitor.<init>(OccurrencesVisitor.java:105)
at com.python.pydev.analysis.OccurrencesAnalyzer.analyzeDocument(OccurrencesAnalyzer.java:50)
at com.python.pydev.analysis.builder.AnalysisBuilderRunnable.doAnalysis(AnalysisBuilderRunnable.java:271)
at com.python.pydev.analysis.builder.AbstractAnalysisBuilderRunnable.run(AbstractAnalysisBuilderRunnable.java:162)
at org.python.pydev.core.concurrency.RunnableAsJobsPoolThread$1.run(RunnableAsJobsPoolThread.java:140)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
So, apparently the error is this
ModuleNotFoundError: No module named '_pydevd_bundle'
I tried reinstalling PyDev (it looks like the installation might be broken), but to no avail. Ideas?
I might have actually found the issue. I discovered the WinPython distribution I installed was "WinPython Zero", which comes with no additional packages. I uninstalled it and installed the "default" WinPython; now the debugger is working as expected. I suppose then there's some library needed to enable debugging. Maybe a more informative error message would help here, as this one I got really doesn't say much.
Funny thing, that's exactly what happens in PyCharm too: https://youtrack.jetbrains.com/issue/PY-24198

Import not working when file is located in same directory and calling script

I'm not sure if the title of this question is correct, mods please feel free to change it.
I'm working through cs231n Convolutional Neural Networks for Visual Recognition course online and I've hit a weird error. This is my first attempt at any real Python programming so it could be a simple error, or something more complicated.
I'm using Python 2.7, Anaconda, and Windows 7.
When trying to run a script I get the following error;
NameError: global name 'im2col_cython' is not defined
My understanding so far is that this occurs because this fails (and calls the exception);
try:
from cs231n.im2col_cython import col2im_cython, im2col_cython
from cs231n.im2col_cython import col2im_6d_cython
except ImportError:
print 'run the following from the cs231n directory and try again:'
print 'python setup.py build_ext --inplace'
print 'You may also need to restart your iPython kernel'
I've tried to figure out why this may be the case. First off I have to run setup.py to turn im2col_cython.pyx into other files. This seems to run but does at one point have the warning;
warning: extension name 'im2col_cython' does not match fully qualified name 'cs231n.im2col_cython' of 'im2col_cython.pyx'
My figuring here is that it's an issue to do with the fact that the folder tree I have looks like this;
Assignment 2
->cs231n
Inside cs231n is where the setup.py and im2col_cython.pyx files are located. I've installed cython, and I have vc for python2.7 installed. When I run setup.py is creates 2 new files;
im2col_cython.c
im2col_cython.pyd
But I have no idea if that's what it's meant to do or anything. I'm in way over my head with this (0 Python knowledge), but I'm keen to learn!
EDIT 1
The script that imports im2col_cython is here
The im2col_cython file is here
EDIT 2
When including the following in the exception clause;
import traceback; traceback.print_exc()
I get this output;
Traceback (most recent call last):
File "fast_layers.py", line 3, in <module>
from cs231n.im2col_cython import col2im_cython, im2col_cython
ImportError: No module named cs231n.im2col_cython
Add this in the file fast_layer.py before import cs231n.im2col_cython:
import pyximport
pyximport.install()
The problem you mentioned should be fixed.

Plone 4.3.3 - Schema-Driven types - plone.directives.form not importing

I am following the Plone guide for Schema-Driven Types: http://docs.plone.org/external/plone.app.dexterity/docs/prerequisite.html
Running:
Mac OSX 10.8.5 Mountain Lion
Plone 4.3.3 http://plone.org/products/plone/releases/4.3.3
When I get to the second page on Testing the Type, I get an error.
I have the ZCML error below. I have already made sure to do what it says. I did another clean install and received the same error. Here is what it says in the guide.
If Zope doesn’t start up:
Look for error messages on the console, and make sure you start in the foreground with ./bin/instance fg. You could have a syntax error or a ZCML error.
If you have a failed import for plone.directives.form, make sure that you specified the [grok] extra for plone.app.dexterity in your setup.py install_requires.
Error Message:
ZopeXMLConfigurationError: File "/Users/Josh/Documents/Plone4/buildout-cache/eggs/Products.CMFPlone-4.3.3-py2.7.egg/Products/CMFPlone/configure.zcml", line 98.4-102.10
ZopeXMLConfigurationError: File "/Users/Josh/Documents/Plone4/zinstance/src/example.conference/example/conference/configure.zcml", line 18.2-18.27
NameError: name 'form' is not defined
Here is the full log of the error message http://pastie.org/9200196
I figured out what I did with the help of one of the amazing developers at where I work.
On the Setting the schema part of the guide, I did not fully change program.py & session.py.
The arguments change in IProgram to the following below:
class IProgram(model.Schema):
NOT: class IProgram(form.Schema, IImageScaleTraversable):
You must remove only what the guide tells you to remove.

Categories