我目前正在与tensorflow一起开发一款新的带有M1芯片的mac电脑。
正如您可能知道的,让tensorflow在M1芯片上工作有点麻烦,但我在下面的教程中成功地做到了:https://github.com/mrdbourke/m1-machine-learning-test
现在,我有了一个名为tensorflow-test
的环境,其中包含python3.8,并且正确安装了tensorflow (我可以没有错误地导入它)。
在此环境中,我希望使用单击包构建一些命令行。我曾经把一切都完美地整合在一起,直到,由于一些奇怪的原因,我把环境搞砸了,现在我搞不懂到底是怎么回事了。
下面是一个简单的代码来复制我所拥有的内容。在tensorflow-test conda环境中,我有一个文件,单击代码hello.py
。
import click
import tensorflow
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
help='The person to greet.')
def cli(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo("Hello {name}!")
if __name__ == '__main__':
cli()
另一个设置为setup.py
:
from setuptools import setup
setup(
name="hello",
version='0.1',
py_modules=['hello'],
author='xxx',
install_requires=[
'Click',
'pandas',
'tensorflow',
],
entry_points='''
[console_scripts]
hello=hello:cli
''',
)
当我使用python hello.py
运行它时,一切似乎都很好。但是,当我试图将它作为命令行直接运行时,我会这样做。
pip install --editable .
出现以下错误:
Requirement already satisfied: Click in ./env/lib/python3.8/site-packages (from hello==0.1) (8.0.4)
Requirement already satisfied: pandas in ./env/lib/python3.8/site-packages (from hello==0.1) (1.4.2)
ERROR: Could not find a version that satisfies the requirement tensorflow (from hello) (from versions: none)
ERROR: No matching distribution found for tensorflow
我检查了一下,在./env/lib/python3.8/site-packages中有一个名为tensorflow的文件夹。
怎么一回事?为什么我不能直接将hello作为命令使用,否则一切看起来都很好呢?
发布于 2022-04-30 19:18:10
现在看来我已经开始工作了,但是直到现在我还不清楚确切的原因是什么。
我设法检索了旧的环境文件,我意识到在$HOME/tensorflow-test/env/lib/python3.8/site-packages
中,一些与tensorboard相关的文件丢失了。
我的预感是这些是安装在conda install -c apple tensorflow-deps
上面链接的tensorflow依赖项下的
奇怪的是,当运行此命令时,它会产生一个错误,因此使其工作的唯一方法是从我以前的环境中复制粘贴它们.
我会更新,如果我设法找到更多的东西。
编辑:我现在遇到了安装新软件包的问题。
例如,当使用pip install pyautogui
时,一切都满足了,但是当试图在环境中导入它时,会出现如下情况:
Traceback (most recent call last):
File "/Users/luisignaciomenendezgarcia/tensorflow-test/env/lib/python3.8/site-packages/pyautogui/_pyautogui_osx.py", line 5, in <module>
import Quartz
File "/Users/luisignaciomenendezgarcia/tensorflow-test/env/lib/python3.8/site-packages/Quartz/__init__.py", line 110, in <module>
_load()
File "/Users/luisignaciomenendezgarcia/tensorflow-test/env/lib/python3.8/site-packages/Quartz/__init__.py", line 28, in _load
from Quartz import CoreGraphics as m
File "/Users/luisignaciomenendezgarcia/tensorflow-test/env/lib/python3.8/site-packages/Quartz/CoreGraphics/__init__.py", line 13, in <module>
from Quartz.CoreGraphics._inlines import _inline_list_
ImportError: dlopen(/Users/luisignaciomenendezgarcia/tensorflow-test/env/lib/python3.8/site-packages/Quartz/CoreGraphics/_inlines.abi3.so, 0x0002): tried: '/Users/luisignaciomenendezgarcia/tensorflow-test/env/lib/python3.8/site-packages/Quartz/CoreGraphics/_inlines.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_inlines.abi3.so' (no such file), '/usr/lib/_inlines.abi3.so' (no such file)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/luisignaciomenendezgarcia/tensorflow-test/env/lib/python3.8/site-packages/pyautogui/__init__.py", line 166, in <module>
from . import _pyautogui_osx as platformModule
File "/Users/luisignaciomenendezgarcia/tensorflow-test/env/lib/python3.8/site-packages/pyautogui/_pyautogui_osx.py", line 7, in <module>
assert False, "You must first install pyobjc-core and pyobjc: https://pyautogui.readthedocs.io/en/latest/install.html"
AssertionError: You must first install pyobjc-core and pyobjc: https://pyautogui.readthedocs.io/en/latest/install.html
同样的情况也发生在模块键盘上。
不过,如果我将模式排除在环境之外,就没有问题了。
https://stackoverflow.com/questions/72070421
复制相似问题