[Çözüldü] Çalıştıramadığım .py

Başlatan levbay, 04 Ocak 2016 - 10:07:55

« önceki - sonraki »

0 Üyeler ve 1 Ziyaretçi konuyu incelemekte.

levbay

merhabalar;
Ben ubuntuda ve python dilinde yeni sayılırım. Bir projede python kullanmam gerekiyor.
Python arayüz tasarımı için Qt Desinger kullanmaktayım.
Basıt sadece labeldaki yazıyı temizleyen bir arayüz yaptım. Bunu py ye dönüştürdüm ama bir türlü çalıştıramadım.
Uç Birimde kod ile çalıştırmaya çalıştığımda dosyanın ismini yazıp enter a bastığımda 2-3 sn bekleyip yeni satıra geçiyor. hata falan vermiyor.

Masa üstünde mouse ile çalıştır dediğimde ise mouse işlem yapıyormuş gibi gözüküp sonra normale dönüyor.

Aşağıda basit kodu paylaştım.

Yardımcı olursanız memnun olurum.


#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '/home/levent/Belgeler/Deneme/deneme.ui'
#
# Created: Thu Dec 31 16:11:20 2015
#      by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(400, 300)
        self.pushButton = QtGui.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(130, 130, 98, 27))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.label = QtGui.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(140, 60, 66, 17))
        self.label.setObjectName(_fromUtf8("label"))

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.label.clear)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))
        self.pushButton.setText(_translate("Form", "PushButton", None))
        self.label.setText(_translate("Form", "TextLabel", None))


iskenderoguz

uçbirimde çalıştırdım derken tam olarak nasıl çalıştıryorsun. hangi konutları veriyorsun yazarmısın

levbay

Programın olduğu klasöre girip
... $ ./deneme
dediğimde o komut satırında biraz bekliyor sonrasında yeni satıra geçiyor.
./deneme için tanıtımı falan yapmıştım.  usr da bin klasörü açıp kopyalama falan yaptım.







neynefes

deneme.py gibi birşey olması gerekmiyor mu? Konuya hakim değilim sadece python dosyalarını böyle çalıştırıyorum.

levbay

bende hakim değilim. bir projede(medikal cihaz) python kullanmam gerek. Qt Desinger da arayüzleri yapmaya başladım. Proje Raspberry Pi 2 de çalışacak.
ama ilk yaptığım bu basit arayüzü çalıştıramadım ubuntuda. Raspberry pi Debian farketmez herhalde burada çalışna orada da çalışır

neynefes

Python bütün platformlarda çalışabiliyor. Raspide de aynı şekilde çalıştırılır. deneme.py diyerek denediniz mi? Doğru yazıldıysa çalışması gerek.

levbay

...$ python deneme.py diyorum
sonrasında 1-2 sn bekleyip
...$ satırına iniyor ve arayüz gelmiyor.

neynefes

O vakit python bilen birileri baksın. Dediğim gibi dil hakkında bilgim yok.

sayz

#8
deneme dosyasının olduğu dizinde şu komutları yürütüp çıktısını paylaşır mısın lütfen:

python -v deneme.py

mthnzbk


levbay

#10
Alıntı yapılan: sayz - 04 Ocak 2016 - 20:04:20
deneme dosyasının olduğu dizinde şu komutları yürütüp çıktısını paylaşır mısın lütfen:

python -v deneme.py


komutu çalıştırdığımda


# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib/python2.7/site.pyc matches /usr/lib/python2.7/site.py
import site # precompiled from /usr/lib/python2.7/site.pyc
# /usr/lib/python2.7/os.pyc matches /usr/lib/python2.7/os.py
import os # precompiled from /usr/lib/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/lib/python2.7/posixpath.pyc matches /usr/lib/python2.7/posixpath.py
import posixpath # precompiled from /usr/lib/python2.7/posixpath.pyc
# /usr/lib/python2.7/stat.pyc matches /usr/lib/python2.7/stat.py
import stat # precompiled from /usr/lib/python2.7/stat.pyc
# /usr/lib/python2.7/genericpath.pyc matches /usr/lib/python2.7/genericpath.py
import genericpath # precompiled from /usr/lib/python2.7/genericpath.pyc
# /usr/lib/python2.7/warnings.pyc matches /usr/lib/python2.7/warnings.py
import warnings # precompiled from /usr/lib/python2.7/warnings.pyc
# /usr/lib/python2.7/linecache.pyc matches /usr/lib/python2.7/linecache.py
import linecache # precompiled from /usr/lib/python2.7/linecache.pyc
# /usr/lib/python2.7/types.pyc matches /usr/lib/python2.7/types.py
import types # precompiled from /usr/lib/python2.7/types.pyc
# /usr/lib/python2.7/UserDict.pyc matches /usr/lib/python2.7/UserDict.py
import UserDict # precompiled from /usr/lib/python2.7/UserDict.pyc
# /usr/lib/python2.7/_abcoll.pyc matches /usr/lib/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/lib/python2.7/_abcoll.pyc
# /usr/lib/python2.7/abc.pyc matches /usr/lib/python2.7/abc.py
import abc # precompiled from /usr/lib/python2.7/abc.pyc
# /usr/lib/python2.7/_weakrefset.pyc matches /usr/lib/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/lib/python2.7/_weakrefset.pyc
import _weakref # builtin
# /usr/lib/python2.7/copy_reg.pyc matches /usr/lib/python2.7/copy_reg.py
import copy_reg # precompiled from /usr/lib/python2.7/copy_reg.pyc
# /usr/lib/python2.7/traceback.pyc matches /usr/lib/python2.7/traceback.py
import traceback # precompiled from /usr/lib/python2.7/traceback.pyc
# /usr/lib/python2.7/sysconfig.pyc matches /usr/lib/python2.7/sysconfig.py
import sysconfig # precompiled from /usr/lib/python2.7/sysconfig.pyc
# /usr/lib/python2.7/re.pyc matches /usr/lib/python2.7/re.py
import re # precompiled from /usr/lib/python2.7/re.pyc
# /usr/lib/python2.7/sre_compile.pyc matches /usr/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/lib/python2.7/sre_parse.pyc matches /usr/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/lib/python2.7/sre_parse.pyc
# /usr/lib/python2.7/sre_constants.pyc matches /usr/lib/python2.7/sre_constants.py
import sre_constants # precompiled from /usr/lib/python2.7/sre_constants.pyc
import _locale # builtin
# /usr/lib/python2.7/_sysconfigdata.pyc matches /usr/lib/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/lib/python2.7/_sysconfigdata.pyc
# /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.pyc matches /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.py
import _sysconfigdata_nd # precompiled from /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.pyc
# /usr/lib/python2.7/sitecustomize.pyc matches /usr/lib/python2.7/sitecustomize.py
import sitecustomize # precompiled from /usr/lib/python2.7/sitecustomize.pyc
import encodings # directory /usr/lib/python2.7/encodings
# /usr/lib/python2.7/encodings/__init__.pyc matches /usr/lib/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/lib/python2.7/encodings/__init__.pyc
# /usr/lib/python2.7/codecs.pyc matches /usr/lib/python2.7/codecs.py
import codecs # precompiled from /usr/lib/python2.7/codecs.pyc
import _codecs # builtin
# /usr/lib/python2.7/encodings/aliases.pyc matches /usr/lib/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib/python2.7/encodings/aliases.pyc
# /usr/lib/python2.7/encodings/utf_8.pyc matches /usr/lib/python2.7/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib/python2.7/encodings/utf_8.pyc
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
python: can't open file 'deneme.py': [Errno 2] No such file or directory
ubuntu:~/Masaüstü$


Konsol uygulamalarını çalıştırıyorum ama arayüz uygulamaları dönüştürdüğüm halde çalışmıyor.


Mesaj tekrarı yüzünden mesajınız birleştirildi. Bu mesajın gönderim tarihi : 05 Ocak 2016 - 14:32:30

Alıntı yapılan: mthnzbk - 04 Ocak 2016 - 21:04:31
http://wiki.pisilinux.org/tr/index.php?title=PyQt_dersleri_-_1 Burayı okursan büyük ihtimal çözümü bulacaksın.

buradaki gui örneğini yaptğımda da çalışmadı. Acaba python kurulumunda mı bir sıkıntı var ?Kütüphane falan mı  yükle değil acaba ?

mthnzbk

Bir şeyi yanlış yapıyorda olabilirsin. Ben genelde designerin ürettiği kodu kullanmam. İstersen kendi tarzımla yazdığın sınıfı düzeltebilirim. Eğer python biliyorsan zaten her türlü anlarsın.

sayz

Alıntı yapılan: levbay - 05 Ocak 2016 - 09:39:53




komutu çalıştırdığımda


# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib/python2.7/site.pyc matches /usr/lib/python2.7/site.py
import site # precompiled from /usr/lib/python2.7/site.pyc
# /usr/lib/python2.7/os.pyc matches /usr/lib/python2.7/os.py
import os # precompiled from /usr/lib/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/lib/python2.7/posixpath.pyc matches /usr/lib/python2.7/posixpath.py
import posixpath # precompiled from /usr/lib/python2.7/posixpath.pyc
# /usr/lib/python2.7/stat.pyc matches /usr/lib/python2.7/stat.py
import stat # precompiled from /usr/lib/python2.7/stat.pyc
# /usr/lib/python2.7/genericpath.pyc matches /usr/lib/python2.7/genericpath.py
import genericpath # precompiled from /usr/lib/python2.7/genericpath.pyc
# /usr/lib/python2.7/warnings.pyc matches /usr/lib/python2.7/warnings.py
import warnings # precompiled from /usr/lib/python2.7/warnings.pyc
# /usr/lib/python2.7/linecache.pyc matches /usr/lib/python2.7/linecache.py
import linecache # precompiled from /usr/lib/python2.7/linecache.pyc
# /usr/lib/python2.7/types.pyc matches /usr/lib/python2.7/types.py
import types # precompiled from /usr/lib/python2.7/types.pyc
# /usr/lib/python2.7/UserDict.pyc matches /usr/lib/python2.7/UserDict.py
import UserDict # precompiled from /usr/lib/python2.7/UserDict.pyc
# /usr/lib/python2.7/_abcoll.pyc matches /usr/lib/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/lib/python2.7/_abcoll.pyc
# /usr/lib/python2.7/abc.pyc matches /usr/lib/python2.7/abc.py
import abc # precompiled from /usr/lib/python2.7/abc.pyc
# /usr/lib/python2.7/_weakrefset.pyc matches /usr/lib/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/lib/python2.7/_weakrefset.pyc
import _weakref # builtin
# /usr/lib/python2.7/copy_reg.pyc matches /usr/lib/python2.7/copy_reg.py
import copy_reg # precompiled from /usr/lib/python2.7/copy_reg.pyc
# /usr/lib/python2.7/traceback.pyc matches /usr/lib/python2.7/traceback.py
import traceback # precompiled from /usr/lib/python2.7/traceback.pyc
# /usr/lib/python2.7/sysconfig.pyc matches /usr/lib/python2.7/sysconfig.py
import sysconfig # precompiled from /usr/lib/python2.7/sysconfig.pyc
# /usr/lib/python2.7/re.pyc matches /usr/lib/python2.7/re.py
import re # precompiled from /usr/lib/python2.7/re.pyc
# /usr/lib/python2.7/sre_compile.pyc matches /usr/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/lib/python2.7/sre_parse.pyc matches /usr/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/lib/python2.7/sre_parse.pyc
# /usr/lib/python2.7/sre_constants.pyc matches /usr/lib/python2.7/sre_constants.py
import sre_constants # precompiled from /usr/lib/python2.7/sre_constants.pyc
import _locale # builtin
# /usr/lib/python2.7/_sysconfigdata.pyc matches /usr/lib/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/lib/python2.7/_sysconfigdata.pyc
# /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.pyc matches /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.py
import _sysconfigdata_nd # precompiled from /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.pyc
# /usr/lib/python2.7/sitecustomize.pyc matches /usr/lib/python2.7/sitecustomize.py
import sitecustomize # precompiled from /usr/lib/python2.7/sitecustomize.pyc
import encodings # directory /usr/lib/python2.7/encodings
# /usr/lib/python2.7/encodings/__init__.pyc matches /usr/lib/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/lib/python2.7/encodings/__init__.pyc
# /usr/lib/python2.7/codecs.pyc matches /usr/lib/python2.7/codecs.py
import codecs # precompiled from /usr/lib/python2.7/codecs.pyc
import _codecs # builtin
# /usr/lib/python2.7/encodings/aliases.pyc matches /usr/lib/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib/python2.7/encodings/aliases.pyc
# /usr/lib/python2.7/encodings/utf_8.pyc matches /usr/lib/python2.7/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib/python2.7/encodings/utf_8.pyc
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
python: can't open file 'deneme.py': [Errno 2] No such file or directory
ubuntu:~/Masaüstü$

deneme.py diye bir dosyanız yok ki sizin? bu komutu deneme.py dosyanızın olduğu dizinde vereceksiniz.

python betiğinizin olduğu dizinde şu komutu verin:

python -v "dosya_ismi.py" "dosya_ismi" yerine kendi dosyanızın ismini yazın

mthnzbk

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '/home/levent/Belgeler/Deneme/deneme.ui'
#
# Created: Thu Dec 31 16:11:20 2015
#      by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class Form(QWidget):
    def __init__(self, parent=None):
        super().__init__()
        self.resize(400, 300)
        self.pushButton = QPushButton(self)
        self.pushButton.setGeometry(QRect(130, 130, 98, 27))
        self.label = QLabel(self)

        self.setWindowTitle("Form")
        self.pushButton.setText("PushButton")
        self.label.setText("TextLabel")


if __name__ == "__main__":
    app = QApplication([])
    gui = Form()
    gui.show()
    sys.exit(app.exec_())


pyqt5 olarak kodu düzenledim. Bu örnek üzerinden el ile yazarak devam ederseniz öğrenmeniz de kolay olur. Not: PyQt4 eskidi. Zaten bilmediğin için doğrudan PyQt5 kullanman iyi olur.

sayz

@mthnzbk'a da katılıyorum. otomatik oluşturulan kodlara güvenme. qt bilgilerim eskidiği için pek kodlara bakmadım ama kendin elle yazarak ilerlemen daha faydalı olur.

levbay

Öncelikle hepinize teşekkür ediyorum. Çalıştıramama hatası tamamen benden kaynaklı. Dikkat eksikliği kaynaklı...
Şöyleki; ui dosyasını çeviriyorum ve ben direkt onu çalıştırmaya çalışıyordum. Çevrilen py dosyasını çalıştırmak için başka bir py dosyası yazıyorum ve o poy dosyasını import ederek kullanıyorum.

bazı kaynaklardan bakarak yapmış olduğum ilk çalışan kodları burada paylaşayım belki birilerinin işine yarar...
Ümit ÖZTOSUN un slaytından da faydalandığımı belirtmek isterim..

ui den dönüştürülmüş py aşağıda

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'ui_messageform.ui'
#
# Created by: PyQt5 UI code generator 5.5.1
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MessageForm(object):
    def setupUi(self, MessageForm):
        MessageForm.setObjectName("MessageForm")
        MessageForm.resize(251, 243)
        self.widget = QtWidgets.QWidget(MessageForm)
        self.widget.setGeometry(QtCore.QRect(0, 0, 251, 241))
        self.widget.setObjectName("widget")
        self.gridLayout = QtWidgets.QGridLayout(self.widget)
        self.gridLayout.setObjectName("gridLayout")
        self.groupBox = QtWidgets.QGroupBox(self.widget)
        self.groupBox.setObjectName("groupBox")
        self.label = QtWidgets.QLabel(self.groupBox)
        self.label.setGeometry(QtCore.QRect(70, 70, 47, 13))
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 2)
        self.btnMesajK = QtWidgets.QPushButton(self.widget)
        self.btnMesajK.setObjectName("btnMesajK")
        self.gridLayout.addWidget(self.btnMesajK, 1, 0, 1, 1)
        self.btnMesajU = QtWidgets.QPushButton(self.widget)
        self.btnMesajU.setObjectName("btnMesajU")
        self.gridLayout.addWidget(self.btnMesajU, 1, 1, 1, 1)

        self.retranslateUi(MessageForm)
        self.btnMesajK.clicked.connect(self.btnMesajK_clicked)
        self.btnMesajU.clicked.connect(self.btnMesajU_clicked)
        QtCore.QMetaObject.connectSlotsByName(MessageForm)

    def btnMesajK_clicked(self):
        self.label.setText(u'Mesajcık')

    def btnMesajU_clicked(self):
        self.label.setText(u'Bu bir mesaj daha ne olsun mesaj işte hop mesaj bazıları mesaş diye yazarlar')
     
    def retranslateUi(self, MessageForm):
        _translate = QtCore.QCoreApplication.translate
        MessageForm.setWindowTitle(_translate("MessageForm", "Message Form"))
        self.groupBox.setTitle(_translate("MessageForm", " Mesaj "))
        self.label.setText(_translate("MessageForm", "TextLabel"))
        self.btnMesajK.setText(_translate("MessageForm", "Kısa Mesaj"))
        self.btnMesajU.setText(_translate("MessageForm", "Uzun Mesaj"))



Bunu import edip çalıştıran py kodları ise


#!/usr/bin/env python
# _*_ coding: utf-8 _*_
#message.py

import sys
from PyQt5.Qt import *
from ui_messageform import Ui_MessageForm

class Message(QWidget, Ui_MessageForm):
    def __init__(self):
        QWidget.__init__(self)
        self.setupUi(self)
       
                     
if __name__== '__main__':
    app = QApplication(sys.argv)
    form = Message()
    form.show()
    app.exec_()

neynefes

Geri bildirim için teşekkürler. Konu hakkında ekleme yapmak isteyen olursa başlığı açabiliriz tekrar.