【发布时间】:2021-01-29 18:48:33
【问题描述】:
我正在构建一个包(然后将其上传到 pypi)。我在这个包中有 3 个模块。这些包有一些依赖项,如 numpy、cv2 等。
所以,我在 setup.py 文件中提到了我的依赖项。
# -*- coding: utf-8 -*-
import setuptools
setuptools.setup(
name='StyleTransferTensorFlow',
url='https://github.com/LordHarsh/Neural_Style_Transfer',
author='Hash Banka',
author_email='harshbanka321@gmail.com',
packages=setuptools.find_packages(),
# Needed for dependencies
install_requires=['matplotlib','tensorflow','os-win','ffmpy','glob2', 'pytest-shutil', 'pytube', 'opencv-python', 'pillow', 'numpy', 'tensorflow_hub'],
version='0.0.8',
# The license can be anything you like
license='MIT',
description="Package to apply style transfer on different frames of a video",
# We will also need a readme eventually (there will be a warning)
# long_description=open('README.txt').read(),
python_requires='>=3.6',
)
我还将它们导入到与模块位于同一目录中的 init.py 文件中。
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
from pytube import YouTube
import os
import cv2
from PIL import Image
import shutil
import glob
import ffmpy
但是当我在模块中执行代码时仍然出现错误
NameError: name 'cv2' is not defined
我不确定为什么我的导入没有运行。 我在一个模块中使用了 cv2 来完成这项任务。 所以我不确定我做错了什么。请帮帮我。
【问题讨论】:
-
除了
init.py之外的其他模块你能import cv2吗? -
我正在使用 google colab 工作。当我在 colab 中直接使用 import 命令时,它可以工作。但是 init.py 中的导入不起作用。我想要的是,当我使用包中的任何内容时,它会自动导入所需的包,如 cv2、numpy 等。那么你能告诉我在哪里可以写我的导入命令吗?谢谢。
标签: python python-3.x package