반응형

$ pip install mysqlclient

Collecting mysqlclient

  Downloading https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz (85kB)

    100% |████████████████████████████████| 92kB 535kB/s 

    Complete output from command python setup.py egg_info:

    /bin/sh: mysql_config: command not found

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/private/var/folders/50/flbhnc592cdd9bdvjz31g85c0000gn/T/pip-install-7x42pkjs/mysqlclient/setup.py", line 16, in <module>

        metadata, options = get_config()

      File "/private/var/folders/50/flbhnc592cdd9bdvjz31g85c0000gn/T/pip-install-7x42pkjs/mysqlclient/setup_posix.py", line 51, in get_config

        libs = mysql_config("libs")

      File "/private/var/folders/50/flbhnc592cdd9bdvjz31g85c0000gn/T/pip-install-7x42pkjs/mysqlclient/setup_posix.py", line 29, in mysql_config

        raise EnvironmentError("%s not found" % (_mysql_config_path,))

    OSError: mysql_config not found

    

    ----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/50/flbhnc592cdd9bdvjz31g85c0000gn/T/pip-install-7x42pkjs/mysqlclient/

 

난 로컬에 mysql을 설치하였으므로 mysql_config가 있는 위치를 패스에 추가해서 설치해봤는데도 못읽어옴

 

mysql-connector-c를 설치해줘야한다고 해서 설치

brew install mysql-connector-c

했더니 에러메시지가 달라짐

 

$ pip install mysqlclient

Collecting mysqlclient

  Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz

    Complete output from command python setup.py egg_info:

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/private/var/folders/50/flbhnc592cdd9bdvjz31g85c0000gn/T/pip-install-4z_dh6jw/mysqlclient/setup.py", line 16, in <module>

        metadata, options = get_config()

      File "/private/var/folders/50/flbhnc592cdd9bdvjz31g85c0000gn/T/pip-install-4z_dh6jw/mysqlclient/setup_posix.py", line 53, in get_config

        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]

      File "/private/var/folders/50/flbhnc592cdd9bdvjz31g85c0000gn/T/pip-install-4z_dh6jw/mysqlclient/setup_posix.py", line 53, in <listcomp>

        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]

      File "/private/var/folders/50/flbhnc592cdd9bdvjz31g85c0000gn/T/pip-install-4z_dh6jw/mysqlclient/setup_posix.py", line 12, in dequote

        raise Exception("Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id=86971 ?")

    Exception: Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id=86971 ?

 

위 주소로 가봤는데 case만 오픈되어있는 상태였다.

 

다르게 검색해봤더니 mysqlclient가 macOS에서 bug가 있고, 깃허브에 해결방법이 나와있었음

https://github.com/PyMySQL/mysqlclient-python#board

 

PyMySQL/mysqlclient-python

MySQL database connector for Python (with Python 3 support) - PyMySQL/mysqlclient-python

github.com

소스 수정하고 다시 설치하니 잘 되더이다.

 

 

반응형
반응형

Python 3.7에서 가상환경 만들어서 superset 설치 진행

https://superset.incubator.apache.org/installation.html

 

Installation & Configuration — Apache Superset documentation

Getting Started Superset has deprecated support for Python 2.* and supports only ~=3.6 to take advantage of the newer Python features and reduce the burden of supporting previous versions. We run our test suite against 3.6, but running on 3.7 should work a

superset.incubator.apache.org

2번째 # User 생성하는 과정에서 에러 발생

Was unable to import superset Error: cannot import name '_maybe_box_datetimelike' from 'pandas.core.common' (/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/pandas/core/common.py)

 

설치화면에서 나와 python에서 import해보니까 안되고, 혹시나 싶어 아나콘다 커스텀버전에서 해당 모듈을 import하니 에러가 안난다.

deprecated가 됬나 검색해보니 최신버전에서는 앞에 언더바가 빠진 형태로 배포된 듯

 

superset/dataframe.py로 들어가 _maybe_box_datetimelike에서 앞에 언더바(_)를 제거한 후 저장

https://github.com/apache/incubator-superset/issues/6770

 

Was unable to import superset Error: cannot import name '_maybe_box_datetimelike' · Issue #6770 · apache/incubator-superset

Superset version Superset version 0.28.1 python 3.6.6 (superset) [root@superset opt]# fabmanager create-admin --app superset Username [admin]: admin User first name [admin]: admin User last name [u...

github.com

 

$ superset db upgrade

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.

INFO  [alembic.runtime.migration] Will assume transactional DDL.

INFO  [alembic.runtime.migration] Running upgrade  -> 4e6a06bad7a8, Init

INFO  [alembic.runtime.migration] Running upgrade 4e6a06bad7a8 -> 5a7bad26f2a7, empty message

INFO  [alembic.runtime.migration] Running upgrade 5a7bad26f2a7 -> 1e2841a4128, empty message

INFO  [alembic.runtime.migration] Running upgrade 1e2841a4128 -> 2929af7925ed, TZ offsets in data sources

INFO  [alembic.runtime.migration] Running upgrade 2929af7925ed -> 289ce07647b, Add encrypted password field

INFO  [alembic.runtime.migration] Running upgrade 289ce07647b -> 1a48a5411020, adding slug to dash

INFO  [alembic.runtime.migration] Running upgrade 1a48a5411020 -> 315b3f4da9b0, adding log model

INFO  [alembic.runtime.migration] Running upgrade 315b3f4da9b0 -> 55179c7f25c7, sqla_descr

INFO  [alembic.runtime.migration] Running upgrade 55179c7f25c7 -> 12d55656cbca, is_featured

/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/alembic/util/messaging.py:73: UserWarning: Skipping unsupported ALTER for creation of implicit constraint

  warnings.warn(msg)

INFO  [alembic.runtime.migration] Running upgrade 12d55656cbca -> 2591d77e9831, user_id

INFO  [alembic.runtime.migration] Running upgrade 2591d77e9831 -> 8e80a26a31db, empty message

INFO  [alembic.runtime.migration] Running upgrade 8e80a26a31db -> 7dbf98566af7, empty message

INFO  [alembic.runtime.migration] Running upgrade 7dbf98566af7 -> 43df8de3a5f4, empty message

INFO  [alembic.runtime.migration] Running upgrade 43df8de3a5f4 -> d827694c7555, css templates

INFO  [alembic.runtime.migration] Running upgrade d827694c7555 -> 430039611635, log more

INFO  [alembic.runtime.migration] Running upgrade 430039611635 -> 18e88e1cc004, making audit nullable

INFO  [alembic.runtime.migration] Running upgrade 18e88e1cc004 -> 836c0bf75904, cache_timeouts

INFO  [alembic.runtime.migration] Running upgrade 18e88e1cc004 -> a2d606a761d9, adding favstar model

INFO  [alembic.runtime.migration] Running upgrade a2d606a761d9, 836c0bf75904 -> d2424a248d63, empty message

INFO  [alembic.runtime.migration] Running upgrade d2424a248d63 -> 763d4b211ec9, fixing audit fk

INFO  [alembic.runtime.migration] Running upgrade d2424a248d63 -> 1d2ddd543133, log dt

INFO  [alembic.runtime.migration] Running upgrade 1d2ddd543133, 763d4b211ec9 -> fee7b758c130, empty message

INFO  [alembic.runtime.migration] Running upgrade fee7b758c130 -> 867bf4f117f9, Adding extra field to Database model

INFO  [alembic.runtime.migration] Running upgrade 867bf4f117f9 -> bb51420eaf83, add schema to table model

INFO  [alembic.runtime.migration] Running upgrade bb51420eaf83 -> b4456560d4f3, change_table_unique_constraint

INFO  [alembic.runtime.migration] Running upgrade b4456560d4f3 -> 4fa88fe24e94, owners_many_to_many

INFO  [alembic.runtime.migration] Running upgrade 4fa88fe24e94 -> c3a8f8611885, Materializing permission

INFO  [alembic.runtime.migration] Running upgrade c3a8f8611885 -> f0fbf6129e13, Adding verbose_name to tablecolumn

INFO  [alembic.runtime.migration] Running upgrade f0fbf6129e13 -> 956a063c52b3, adjusting key length

INFO  [alembic.runtime.migration] Running upgrade 956a063c52b3 -> 1226819ee0e3, Fix wrong constraint on table columns

INFO  [alembic.runtime.migration] Running upgrade 1226819ee0e3 -> d8bc074f7aad, Add new field 'is_restricted' to SqlMetric and DruidMetric

INFO  [alembic.runtime.migration] Running upgrade d8bc074f7aad -> 27ae655e4247, Make creator owners

INFO  [alembic.runtime.migration] Running upgrade 27ae655e4247 -> 960c69cb1f5b, add dttm_format related fields in table_columns

INFO  [alembic.runtime.migration] Running upgrade 960c69cb1f5b -> f162a1dea4c4, d3format_by_metric

INFO  [alembic.runtime.migration] Running upgrade f162a1dea4c4 -> ad82a75afd82, Update models to support storing the queries.

INFO  [alembic.runtime.migration] Running upgrade ad82a75afd82 -> 3c3ffe173e4f, add_sql_string_to_table

INFO  [alembic.runtime.migration] Running upgrade 3c3ffe173e4f -> 41f6a59a61f2, database options for sql lab

INFO  [alembic.runtime.migration] Running upgrade 41f6a59a61f2 -> 4500485bde7d, allow_run_sync_async

INFO  [alembic.runtime.migration] Running upgrade 4500485bde7d -> 65903709c321, allow_dml

INFO  [alembic.runtime.migration] Running upgrade 41f6a59a61f2 -> 33d996bcc382

INFO  [alembic.runtime.migration] Running upgrade 33d996bcc382, 65903709c321 -> b347b202819b, empty message

INFO  [alembic.runtime.migration] Running upgrade b347b202819b -> 5e4a03ef0bf0, Add access_request table to manage requests to access datastores.

INFO  [alembic.runtime.migration] Running upgrade 5e4a03ef0bf0 -> eca4694defa7, sqllab_setting_defaults

INFO  [alembic.runtime.migration] Running upgrade eca4694defa7 -> ab3d66c4246e, add_cache_timeout_to_druid_cluster

INFO  [alembic.runtime.migration] Running upgrade eca4694defa7 -> 3b626e2a6783, Sync DB with the models.py.

WARNI [root] Constraint must have a name

INFO  [alembic.runtime.migration] Running upgrade 3b626e2a6783, ab3d66c4246e -> ef8843b41dac, empty message

INFO  [alembic.runtime.migration] Running upgrade ef8843b41dac -> b46fa1b0b39e, Add json_metadata to the tables table.

INFO  [alembic.runtime.migration] Running upgrade b46fa1b0b39e -> 7e3ddad2a00b, results_key to query

INFO  [alembic.runtime.migration] Running upgrade 7e3ddad2a00b -> ad4d656d92bc, Add avg() to default metrics

INFO  [alembic.runtime.migration] Running upgrade ad4d656d92bc -> c611f2b591b8, dim_spec

INFO  [alembic.runtime.migration] Running upgrade c611f2b591b8 -> e46f2d27a08e, materialize perms

INFO  [alembic.runtime.migration] Running upgrade e46f2d27a08e -> f1f2d4af5b90, Enable Filter Select

INFO  [alembic.runtime.migration] Running upgrade e46f2d27a08e -> 525c854f0005, log_this_plus

INFO  [alembic.runtime.migration] Running upgrade 525c854f0005, f1f2d4af5b90 -> 6414e83d82b7, empty message

INFO  [alembic.runtime.migration] Running upgrade 6414e83d82b7 -> 1296d28ec131, Adds params to the datasource (druid) table

INFO  [alembic.runtime.migration] Running upgrade 1296d28ec131 -> f18570e03440, Add index on the result key to the query table.

INFO  [alembic.runtime.migration] Running upgrade f18570e03440 -> bcf3126872fc, Add keyvalue table

INFO  [alembic.runtime.migration] Running upgrade f18570e03440 -> db0c65b146bd, update_slice_model_json

INFO  [alembic.runtime.migration] Running upgrade db0c65b146bd -> a99f2f7c195a, rewriting url from shortner with new format

INFO  [alembic.runtime.migration] Running upgrade a99f2f7c195a, bcf3126872fc -> d6db5a5cdb5d, empty message

INFO  [alembic.runtime.migration] Running upgrade d6db5a5cdb5d -> b318dfe5fb6c, adding verbose_name to druid column

INFO  [alembic.runtime.migration] Running upgrade d6db5a5cdb5d -> 732f1c06bcbf, add fetch values predicate

INFO  [alembic.runtime.migration] Running upgrade 732f1c06bcbf, b318dfe5fb6c -> ea033256294a, empty message

INFO  [alembic.runtime.migration] Running upgrade b318dfe5fb6c -> db527d8c4c78, Add verbose name to DruidCluster and Database

INFO  [alembic.runtime.migration] Running upgrade db527d8c4c78, ea033256294a -> 979c03af3341, empty message

INFO  [alembic.runtime.migration] Running upgrade 979c03af3341 -> a6c18f869a4e, query.start_running_time

INFO  [alembic.runtime.migration] Running upgrade a6c18f869a4e -> 2fcdcb35e487, saved_queries

INFO  [alembic.runtime.migration] Running upgrade 2fcdcb35e487 -> a65458420354, add_result_backend_time_logging

INFO  [alembic.runtime.migration] Running upgrade a65458420354 -> ca69c70ec99b, tracking_url

INFO  [alembic.runtime.migration] Running upgrade ca69c70ec99b -> a9c47e2c1547, add impersonate_user to dbs

INFO  [alembic.runtime.migration] Running upgrade ca69c70ec99b -> ddd6ebdd853b, annotations

INFO  [alembic.runtime.migration] Running upgrade a9c47e2c1547, ddd6ebdd853b -> d39b1e37131d, empty message

INFO  [alembic.runtime.migration] Running upgrade ca69c70ec99b -> 19a814813610, Adding metric warning_text

INFO  [alembic.runtime.migration] Running upgrade 19a814813610, a9c47e2c1547 -> 472d2f73dfd4, empty message

INFO  [alembic.runtime.migration] Running upgrade 472d2f73dfd4, d39b1e37131d -> f959a6652acd, empty message

INFO  [alembic.runtime.migration] Running upgrade f959a6652acd -> 4736ec66ce19, empty message

/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/sqlalchemy/dialects/sqlite/base.py:1838: SAWarning: WARNING: SQL-parsed foreign key constraint '('datasource_name', 'datasources', 'datasource_name')' could not be located in PRAGMA foreign_keys for table metrics

  "foreign_keys for table %s" % (sig, table_name)

INFO  [alembic.runtime.migration] Running upgrade 4736ec66ce19 -> 67a6ac9b727b, update_spatial_params

INFO  [alembic.runtime.migration] Running upgrade 67a6ac9b727b -> 21e88bc06c02

INFO  [alembic.runtime.migration] Running upgrade 21e88bc06c02 -> e866bd2d4976, smaller_grid

Revision ID: e866bd2d4976

Revises: 21e88bc06c02

Create Date: 2018-02-13 08:07:40.766277

INFO  [alembic.runtime.migration] Running upgrade e866bd2d4976 -> e68c4473c581, allow_multi_schema_metadata_fetch

INFO  [alembic.runtime.migration] Running upgrade e68c4473c581 -> f231d82b9b26, empty message

INFO  [alembic.runtime.migration] Running upgrade f231d82b9b26 -> bf706ae5eb46, cal_heatmap_metric_to_metrics

INFO  [alembic.runtime.migration] Running upgrade f231d82b9b26 -> 30bb17c0dc76, empty message

INFO  [alembic.runtime.migration] Running upgrade 30bb17c0dc76, bf706ae5eb46 -> c9495751e314, empty message

INFO  [alembic.runtime.migration] Running upgrade f231d82b9b26 -> 130915240929, is_sqllab_view

INFO  [alembic.runtime.migration] Running upgrade 130915240929, c9495751e314 -> 5ccf602336a0, empty message

INFO  [alembic.runtime.migration] Running upgrade 5ccf602336a0 -> e502db2af7be, add template_params to tables

INFO  [alembic.runtime.migration] Running upgrade e502db2af7be -> c5756bec8b47, Time grain SQLA

INFO  [alembic.runtime.migration] Running upgrade c5756bec8b47 -> afb7730f6a9c, remove empty filters

INFO  [alembic.runtime.migration] Running upgrade afb7730f6a9c -> 80a67c5192fa, single pie chart metric

INFO  [alembic.runtime.migration] Running upgrade 80a67c5192fa -> bddc498dd179, adhoc filters

INFO  [alembic.runtime.migration] Running upgrade bddc498dd179 -> 3dda56f1c4c6, Migrate num_period_compare and period_ratio_type

INFO  [alembic.runtime.migration] Running upgrade 3dda56f1c4c6 -> 1d9e835a84f9, empty message

INFO  [alembic.runtime.migration] Running upgrade bddc498dd179 -> 4451805bbaa1, remove double percents

Traceback (most recent call last):

  File "/Users/gsinworld/Documents/Program/env-superset/bin/superset", line 15, in <module>

    cli()

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/click/core.py", line 722, in __call__

    return self.main(*args, **kwargs)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/flask/cli.py", line 380, in main

    return AppGroup.main(self, *args, **kwargs)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/click/core.py", line 697, in main

    rv = self.invoke(ctx)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/click/core.py", line 1066, in invoke

    return _process_result(sub_ctx.command.invoke(sub_ctx))

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/click/core.py", line 1066, in invoke

    return _process_result(sub_ctx.command.invoke(sub_ctx))

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/click/core.py", line 895, in invoke

    return ctx.invoke(self.callback, **ctx.params)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/click/core.py", line 535, in invoke

    return callback(*args, **kwargs)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func

    return f(get_current_context(), *args, **kwargs)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/flask/cli.py", line 257, in decorator

    return __ctx.invoke(f, *args, **kwargs)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/click/core.py", line 535, in invoke

    return callback(*args, **kwargs)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/flask_migrate/cli.py", line 134, in upgrade

    _upgrade(directory, revision, sql, tag, x_arg)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/flask_migrate/__init__.py", line 95, in wrapped

    f(*args, **kwargs)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/flask_migrate/__init__.py", line 280, in upgrade

    command.upgrade(config, revision, sql=sql, tag=tag)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/alembic/command.py", line 276, in upgrade

    script.run_env()

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/alembic/script/base.py", line 475, in run_env

    util.load_python_file(self.dir, "env.py")

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 90, in load_python_file

    module = load_module_py(module_id, path)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/alembic/util/compat.py", line 156, in load_module_py

    spec.loader.exec_module(module)

  File "<frozen importlib._bootstrap_external>", line 728, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/superset/migrations/env.py", line 100, in <module>

    run_migrations_online()

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/superset/migrations/env.py", line 93, in run_migrations_online

    context.run_migrations()

  File "<string>", line 8, in run_migrations

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/alembic/runtime/environment.py", line 839, in run_migrations

    self.get_context().run_migrations(**kw)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/alembic/runtime/migration.py", line 361, in run_migrations

    step.migration_fn(**kw)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/superset/migrations/versions/4451805bbaa1_remove_double_percents.py", line 82, in upgrade

    replace('%%', '%')

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/superset/migrations/versions/4451805bbaa1_remove_double_percents.py", line 53, in replace

    .join(Table)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 2235, in join

    from_joinpoint=from_joinpoint,

  File "<string>", line 2, in _join

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/sqlalchemy/orm/base.py", line 220, in generate

    fn(self, *args[1:], **kw)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 2414, in _join

    left, right, onclause, prop, create_aliases, outerjoin, full

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 2437, in _join_left_to_right

    ) = self._join_determine_implicit_left_side(left, right, onclause)

  File "/Users/gsinworld/Documents/Program/env-superset/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 2568, in _join_determine_implicit_left_side

    "Can't determine which FROM clause to join "

sqlalchemy.exc.InvalidRequestError: Can't determine which FROM clause to join from, there are multiple FROMS which can join to this entity. Try adding an explicit ON clause to help resolve the ambiguity.

 

공홈에서 하라는데로 하는데 잘 안된다니.. 찾아보니 SQLAlchemy를 1.2.18로 다운그레이드 하라고 한다.

(현재 설치된 버전은 1.3.2)

 

pip install SQLAlchemy==1.2.18

 

다운그레이드 후 다시 superset db upgrade

(위 에러를 무시하고 진행해봤는데 테이블 생성이 안되서 제대로 실행이 안된다..ㅋㅋ)

 

superset runserver -d

잘 됨. 

 

반응형
반응형

init이 호출되는 시점에 이미 객체(self)가 만들어져 있다

 

dir(인스턴스명) 하면 인스턴스가 가지고 있는 메소드와 속성을 확인할 수 있음

 

>>> dir(my_w)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__','__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'income', 'money', 'now_money', 'owner', 'print_owner_name', 'spend']

 

>>> issubclass(int, object)
True

 

# Method Override(Method를 통째로 다시 씀)

def __init__(self, name, account_no):

    self.account_no = account_no

    #self.owner = name

    #onwer를 지정해주거나 부모클래스의 init을 이용하지 않으면 owner속성을 사용할 수 없음

    super().__init__(name)

 

def __str__(self):

    return '{}의 지갑입니다.'.format(self.owner)

 

>>> print(my_w)
prada의 지갑입니다.

 

def __repr__(self):

    return '{}의 지갑입니다.'.format(self.owner) 

 

>>> my_w
Gucci의 지갑입니다.

반응형
반응형

<range>

range(끝) : 0부터 끝

range(시작, 끝) : 시작부터 끝

range(시작, 끝, 간격) : 시작부터 간격만큼 더하고 끝

끝 숫자를 포함하지 않는다.

 

for i in range(10):

    print(i)

 

결과 : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

 

for i in range(0, 10):

    print(i)

 

결과 : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

 

for i in range(1, 20, 2):

    print(i)

 

결과 : 1, 3, 5, 7, 9 11, 13, 15, 17, 19

<리스트:list>

list_number = [1, 3, 4, 5, 6, 9]

 

for number in list_number:

    print("Your number is ", number, "!!")

 

<딕셔너리:dict>

dict_sample = {

    "key1":"value1",

    "key2":"value2",

    "key3":"value3"

}

 

for dict_key in dict_sample:

    print("display => ", dict_key, "values : ", dict_sample[dict_key])

 

for dict_val in dict_sample.values():

    print("display => ", dict_val)

display =>  key1 values :  value1
display =>  key3 values :  value3
display =>  key2 values :  value2
display =>  value1
display =>  value3
display =>  value2

<break>

numbers = [44, 6, 2, 653, 65, 23, 78, 4, 34, 12]

 

for number in numbers:

    if number == 78:

        print("The number is 78, so I break it.")

        break

    else:

        print("OMG, ", number,"Next time I will find my number.")

else:

    print("Oh My Godness!")

OMG,  44 Next time I will find my number.
OMG,  6 Next time I will find my number.
OMG,  2 Next time I will find my number.
OMG,  653 Next time I will find my number.
OMG,  65 Next time I will find my number.
OMG,  23 Next time I will find my number.
The number is 78, so I break it.

<continue>

numbers = [1, "일", 3, "3", 5]

 

for number in numbers:

    if type(number) is str:

        continue

 

    print("number :",number)

    print("number X 10 :",number*10)

number : 1
number X 10 : 10
number : 3
number X 10 : 30
number : 5
number X 10 : 50

 

반응형
반응형

가상환경까지 셋팅한 후 django-admin startproject [만들어줄프로젝트명]


* test는 사용할 수 없는 이름이다

django-admin startproject test

CommandError: 'test' conflicts with the name of an existing Python module and cannot be used as a project name. Please try another name.


* -(하이픈)은 사용할 수 없나 보다

django-admin startproject test-project

CommandError: 'test-project' is not a valid project name. Please make sure the name is a valid identifier.


<testprj 생성>

django-admin startproject testprj


<실행>

python manage.py runserver


python manage.py startapp firstapp


하게 되면 하위 폴더 및 파일들이 생성됨




settings.py


언어와 시간대를 설정해줘야 한다


LANGUAGE_CODE = 'ko-KR'

TIME_ZONE = 'Asia/Seoul'




Django MTV

M(Model) T(Template) V(View)


- Model : Database관리

- Template : 화면(Html, Css 등)

- View : M과 T를 연결(컨트롤러와 뷰가 합쳐저 있고 템플릿만 빠진 컨셉인가??? 아직 잘 모르겠음)


MVC패턴과 비슷한 것 같은데 용어가 달라 검색해 보았다.

https://docs.djangoproject.com/ko/2.1/faq/general/



반응형
반응형

명령 수행 시 파일&폴더가 생성되기 때문에 폴더를 생성하고 폴더 안에서 명령어를 수행시켜준다.

test-venv라는 파이썬 가상환경을 생성.


ui-MacBook-Pro:~$ mkdir test_venv

ui-MacBook-Pro:~$ cd test_venv

ui-MacBook-Pro:pyvenv_test$ python3 -m venv test-venv

Error: Command '['/Users//pyvenv_test/test-env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1


bin폴더, 심볼릭 링크 등 무언가 생성은 되어 있다. 하지만 activate파일이 없기 때문에 activate시킬 수 없다


<해결과정 1> 

구글링 해보니 --without-pip옵션 주고 만들면 된다고 해서 수행해 보았다


usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]

            [--upgrade] [--without-pip]

            ENV_DIR [ENV_DIR ...]


python3 -m venv test-venv --without-pip


성공!


activate activate.csh activate.fish python python3


activate 파일 생성되고, 수행 확인하였음


source test-venv/bin/activate

(test-venv)-ui-MacBook-Pro:test-venv $


하지만 이렇게 만든 가상환경에서 django를 설치하여 python에서 import하니 import되지 않았다.


<해결과정 2> 

해결과정 1로 진행하여 가상환경에서 pip3 list를 실행 했을 때 엄청나게 많은 패키지가 설치되어 있었다.
python명령어를 실행해본 결과 Anaconda custom 버전임을 확인할 수 있었다.

Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul  2 2016, 17:52:12)


나의 경우 path에서 anaconda/bin이 추가되어 있기 때문에 python3 명령어를 실행 할 경우 

기본으로 아나콘다 폴더 밑 파이썬을 이용하여 수행된 것이고, 따라서 아나콘다 버전의 파이썬으로 가상환경이 생성 된 것.


맥북 샀을 때 한참 러신머닝 수업 들을 때라 파이썬 설치 없이 바로 아나콘다 먼서 설치해서 그런 것 같다.


그래서 바닐라파이썬이 설치되어 있는 $PYTHON_HOME(/usr/local/bin) 폴더를 지정하여 가상환경 생성


$PYTHON_HOME/python3 -m venv test-venv-vl



에러없이 잘 생성되었다.

가상환경 접속 후 pip3 list확인 하니 기본만 설치 되어 있고, django 설치 후 import해보니 잘 진행되었다.



결론 : 여러군데 파이썬이 설치되어 있는 경우 가상환경 생성 시 파이썬 디렉토리를 잘 지정해주도록 하자


반응형
반응형

처음 가입할 때 조그마한 앱 개발로 선택 하니 m10 1달 사용 크레딧 100불인가를 주었지만 

우선 m0으로 시작하였다(쫄보니까)


몽고 아틀라스 무료 리전이 현재 서울, 도쿄는 지원하지 않기 때문에 그나마 가까운 싱가폴 선택하였음


스텝별로 진행하면 됨(1. 유저 생성, 2. 보안 설정, 3. 접속 설정)


1. 유저는 admin User와 CRUD User를 각 한개씩 만들어 주었다.


2. 접속 가능 IP 설정을 해 주고 넘어가야 한다(화이트리스트로 할지, any로 할 지)

2번을 패스하고 3번을 바로 넘어가버리니까 당연하게도 접속이 되지 않았다. 부득이할 경우 any로 열어주고, 

혼자 테스트 해보는 경우 본인의 ip를 화면에서 바로 확인할 수 있으므로 해당 ip를 넣어주도록 하자.


3. 쉘이나 Compass, 각종 프로그램에서 접속 가능한 API 리스트가 있으므로 원하는 것을 이용하면 된다.


쉘화면에서 하기가 빡시므로 주피터 노트북을 이용하는 것으로 하였다.

pip install pymongo
pip install pymongoㅔㅑ


pymongo설치한다


pip install pymongo


jupyter notebook 실행 후


from pymongo import MongoClient

client = MongoClient("mongodb+srv://mongo5:비밀번호@cluster0-ojmhn.mongodb.net/test?retryWrites=true")

db = client.test


잘 붙는 것을 확인하였다.

반응형

+ Recent posts