我有一个错误
TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'
Run Code Online (Sandbox Code Playgroud)
我的代码如下
import os
import cv2
import random
from pathlib import Path
path = Path(__file__).parent
path = "../img_folder"
for f in path.iterdir():
print(f)
f = str(f)
img=cv2.imread(f)
line = random.randint(0, 50)
img[3, 3, :] = line
cv2.imwrite(path + "/" + "photo.png", img)
Run Code Online (Sandbox Code Playgroud)
回溯说代码cv2.imwrite~是错误的。我真的无法理解为什么这是错误的。是这种类型的路径错误吗?还是我使用这种方法是错误的?我应该如何解决这个问题?
我收到错误TypeError:内置操作的错误参数类型.我写
import os
import cv2
from pathlib import Path
path = Path(__file__).parent
path /= "../../img_folder"
for f in path.iterdir():
print(f)
img=cv2.imread(f)
Run Code Online (Sandbox Code Playgroud)
在img = cv2.imread(f)中,错误发生.这是一个Python错误或目录错误吗?在print(f)中,我认为可以获得正确的目录.我该如何解决这个问题?
Bootstrap没有设置为我的Django应用程序.在谷歌控制台,无法加载资源:服务器响应状态为404(未找到)bootflat.min.css错误发生.我在settings.py中写道
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG =True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [os.path.join(BASE_DIR,'bootflat.github.io'), ]
Run Code Online (Sandbox Code Playgroud)
在PythonServer_nginx.conf中
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name MyServerIPAdress; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location /static {
alias /home/ubuntu/PythonServer/PythonServer/accounts/static; # your Django project's static files - amend as required
}
# Finally, send …Run Code Online (Sandbox Code Playgroud) 我收到一个错误,uwsgi的建筑轮子失败。我的环境是Ubuntu,现在我想安装uwsgi,所以我运行命令 pip install uwsgi。但是发生错误
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-9t06jm4_/uwsgi/setup.py", line 126, in <module>
distclass=uWSGIDistribution,
File "/home/ubuntu/anaconda3/lib/python3.5/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/ubuntu/anaconda3/lib/python3.5/site-packages/wheel/bdist_wheel.py", line 215, in run
self.run_command('install')
File "/home/ubuntu/anaconda3/lib/python3.5/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/tmp/pip-build-9t06jm4_/uwsgi/setup.py", line 77, in run
conf = uc.uConf(get_profile())
File "/tmp/pip-build-9t06jm4_/uwsgi/uwsgiconfig.py", line 742, in __init__ …Run Code Online (Sandbox Code Playgroud)我写了以下代码:
import os
import cv2
import random
from pathlib import Path
path = Path(__file__).parent
path = "../img_folder"
for f in path.iterdir():
f = str(f)
img=cv2.imread(f)
im_height = img.shape[0]
im_width = img.shape[1]
Run Code Online (Sandbox Code Playgroud)
但是当我运行此代码时,出现以下错误:
AttributeError: 'NoneType' 对象在 im_height = img.shape[0] 中没有属性 'shape'。
我想我无法访问图像,所以我写了print(img)andprint(type(omg))并且 None& 被返回。img_folder是一个包含 10 个图像的文件夹。当我打印出来时f,我得到:
../img_folder/.DS_Store
我不知道为什么.DS_Store包含因为img_folder只有图像。我应该如何解决这个问题?我应该怎么写这个?为什么我无法访问图像?