我将engine_py3重新命名为engine后,不工作了!python转为了系统的py2。
必须重新初始化venv环境。例如
python3.8 -m venv env
这是因为,路径被写进去了。
./pyftmerge:#!/home/netro/codes/chao_dev/engine_py3/env/bin/python3.8
./f2py3:#!/home/netro/codes/chao_dev/engine_py3/env/bin/python3.8
./activate.fish:set -gx VIRTUAL_ENV "/home/netro/codes/chao_dev/engine_py3/env"
./activate:VIRTUAL_ENV="/home/netro/codes/chao_dev/engine_py3/env"
./hyper:#!/home/netro/codes/chao_dev/engine_py3/env/bin/python3.8
./ttx:#!/home/netro/codes/chao_dev/engine_py3/env/bin/python3.8
./pyrsa-verify:#!/home/netro/codes/chao_dev/engine_py3/env/bin/python3.8
./futurize:#!/home/netro/codes/chao_dev/engine_py3/env/bin/python3.8
./activate.csh:setenv VIRTUAL_ENV "/home/netro/codes/chao_dev/engine_py3/env"
./pyrsa-sign:#!/home/netro/codes/chao_dev/engine_py3/env/bin/python3.8
./fixup_translate_v3beta1_keywords.py:#!/home/netro/codes/chao_dev/engine_py3/env/bin/python3.8
可见activate中写死了路径。
改变后,找不到了。有些stupid。可以用链接,例如 ln -s engine_py3 engine
。可以work
遇到一个奇怪的问题,在Python3中,调用MongoDB。Sorting会影响结果。
基本代码
order = pymongo.DESCENDING if self.descending else pymongo.ASCENDING
items = self.tb.find(cond).sort(self.uid,order).limit(self.limit)
logging.info(f"There are {items.count()} items")
for idx,t in enumerate(items):
logging.info(f"Working on {idx}-th item: {t[self.uid]}")
问题:
找不到原因,可能是某个地方的bug。采用ascending order绕开了这个问题。
python vs cpython vs cython
install (version 0.29.21)
sudo pip install cython
setup.py
from setuptools import setup
from Cython.Build import cythonize
setup(
name='Hello world app',
ext_modules=cythonize(["hello.py","utils.py","config.py"],annotate=True),
zip_safe=False,
)
python setup.py build_ext --inplace
~/engine
: ERROR: error: [Errno 2] No such file or directory: 'engine/hello.so'~/engine/tmp
: OK__init__.py
solves the problem.