相关疑难解决方法(0)

如何在iPython笔记本中调用用argparse编写的模块

我试图将BioPython序列传递给Ilya Stepanov在iPython笔记本环境中实现Ukkonen的后缀树算法.我在argparse组件上遇到了绊脚石.

我之前从未直接与argparse打过交道.如何在不重写main()的情况下使用它?

通过这个,这个Ukkonen算法的写法非常棒.

python bioinformatics suffix-tree ipython biopython

24
推荐指数
4
解决办法
2万
查看次数

为什么我收到此错误: TypeError: 'Namespace' object is not subscriptable

我面临 argparse 库的问题。

我有encodings.pickle 文件,并且我按照下面的代码来识别演员,但加载嵌入似乎不起作用。

这是代码:

ap = argparse.ArgumentParser()
ap.add_argument("-e", "--encodings", required=True,
                help="path to serialized db of facial encodings")
ap.add_argument("-i", "--image", required=True,
                help="path to input image")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
                help="face detection model to use: either `hog` or `cnn`")
ap.add_argument("-fnn", "--fast-nn", action="store_true")
args = parser.parse_args('')
print(args)

# load the known faces and embeddings
print("[INFO] loading encodings...")
data = pickle.loads(open(args["encodings"], "rb").read())
Run Code Online (Sandbox Code Playgroud)

源代码可以在这里找到。

python

12
推荐指数
1
解决办法
2万
查看次数

如何修复ipykernel_launcher.py:错误:jupyter中无法识别的参数?

我在设置了最终可以使用cmd 运行的环境两天后遵循这个tensorflow 教程premade_estimator.py

但是当我尝试在jupyter笔记本中运行相同的代码时,我收到此错误:

usage: ipykernel_launcher.py [-h] [--batch_size BATCH_SIZE]
                             [--train_steps TRAIN_STEPS]

ipykernel_launcher.py: error: unrecognized arguments: -f C:\Users\david\AppData\Roaming\jupyter\runtime\kernel-4faecb24-6e87-40b4-bf15-5d24520d7130.json
Run Code Online (Sandbox Code Playgroud)

发生异常,使用%tb查看完整的回溯.

SystemExit: 2

C:\Anaconda3\envs\python3x\lib\site-packages\IPython\core\interactiveshell.py:2918: 
UserWarning: To exit: use 'exit', 'quit', or Ctrl-D. warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下方法修复它但没有成功:

pip install --ignore-installed --upgrade jupyter

pip install ipykernel
python -m ipykernel install

conda install notebook ipykernel
ipython kernelspec install-self
Run Code Online (Sandbox Code Playgroud)

任何想法都会欣赏!谢谢!

python python-3.x jupyter tensorflow jupyter-notebook

8
推荐指数
3
解决办法
2万
查看次数

在iPython Notebook中调用parse_args()时出现SystemExit:2错误

我正在学习使用Python和scikit-learn并执行以下代码块(最初来自http://scikit-learn.org/stable/auto_examples/document_classification_20newsgroups.html#example-document-classification-20newsgroups-py) iPython笔记本(使用Python 2.7):

from __future__ import print_function
from optparse import OptionParser

# parse commandline arguments
op = OptionParser()
op.add_option("--report",
              action="store_true", dest="print_report",
              help="Print a detailed classification report.")
op.add_option("--chi2_select",
              action="store", type="int", dest="select_chi2",
              help="Select some number of features using a chi-squared test")
op.add_option("--confusion_matrix",
              action="store_true", dest="print_cm",
              help="Print the confusion matrix.")
op.add_option("--top10",
              action="store_true", dest="print_top10",
              help="Print ten most discriminative terms per class"
                   " for every classifier.")
op.add_option("--all_categories",
              action="store_true", dest="all_categories",
              help="Whether to use all categories or not.")
op.add_option("--use_hashing",
              action="store_true",
              help="Use a hashing vectorizer.")
op.add_option("--n_features",
              action="store", …
Run Code Online (Sandbox Code Playgroud)

python optparse ipython-notebook

7
推荐指数
1
解决办法
4672
查看次数

为什么我的argparse系统出现系统出口2错误?

这是我编码的主要部分.当我运行我的整个代码集时,它显示在此段中发生了异常:"options = parse.parse_args()"中的SystemExit2错误.我可以知道这里出了什么问题吗?

import argparse
import queue
import roypy
from sample_camera_info import print_camera_info
from roypy_sample_utils import CameraOpener, add_camera_opener_options
from roypy_platform_utils import PlatformHelper

class MyListener (roypy.IRecordStopListener):
   """A simple listener, in which waitForStop() blocks until onRecordingStopped has been called."""
   def __init__ (self):
       super (MyListener, self).__init__()
       self.queue = queue.Queue()

   def onRecordingStopped (self, frameCount):
       self.queue.put (frameCount)

   def waitForStop (self):
       frameCount = self.queue.get()
       print ("Stopped after capturing {frameCount} frames".format (frameCount=frameCount))

def main ():
    platformhelper = PlatformHelper() 
    parser = argparse.ArgumentParser (usage = __doc__)
    add_camera_opener_options (parser)
    parser.add_argument …
Run Code Online (Sandbox Code Playgroud)

python cpu-word argparse

6
推荐指数
1
解决办法
1271
查看次数

为什么Python的argparse使用SystemExit的错误代码为2?

当我给Python的argparse输入它不喜欢时,它会引发一个代码为2的SystemExit,这似乎意味着"没有这样的文件或目录".为什么要使用此错误代码?

import argparse
import errno

parser = argparse.ArgumentParser()
parser.add_argument('arg')

try:
    parser.parse_args([])
except SystemExit as se:
    print("Got error code {} which is {} in errno"
        .format(se.code, errno.errorcode[se.code]))
Run Code Online (Sandbox Code Playgroud)

产生这个输出:

usage: se.py [-h] arg
se.py: error: too few arguments
Got error code 2 which is ENOENT in errno
Run Code Online (Sandbox Code Playgroud)

python errno argparse

1
推荐指数
1
解决办法
2920
查看次数