pythonpath

OpenCV MacOS源码安装

左心房为你撑大大i 提交于 2019-11-30 06:54:28
在Mac上折腾了一天的OpenCV源码安装,记录一下备忘 正常的步骤: 按照说明文档,下载源码,解压,进入目录 mkdir release cd release cmake -D BUILD_TESTS=OFF .. make -j8 sudo make install 使用cmake生成配置文件的时候可以看一下log,一些依赖包类似libjpeg,libpng等等最好先安装上,最简单的方法就是使用MacPorts来安装,方便管理,以后卸载也容易 看起来过程很简单,但是装完了之后。。。c++很好使,但是python功能使用不了 查看了一下,编译python支持的开关变量为BUILD_NEW_PYTHON_SUPPORT=ON,默认为开启的,应该没有什么问题,上网搜了一下原因,原来是要把cv2.so的路径加入到PYTHONPATH,默认情况下cv2.so文件被安装在/usr/local/lib/python2.7/site-packages,这个值是CMakeCache.txt文件中定义的CMAKE_INSTALL_PREFIX和PYTHON_PACKAGES_PATH这两个变量定义的,具体可查看CMakeCache.txt文件,当然这个值可随意修改,建议保留默认。 在/etc/profile或者~/.bash_profile文件中设置PYTHONPATH环境变量: export

How do I import a Python script from a sibling directory?

偶尔善良 提交于 2019-11-30 04:15:53
Here is the directory structure: parent_dir/ foo_dir/ foo.py bar_dir/ bar.py How do I import bar.py into foo.py? If all occurring directories are Python packages , i.e. they all contain __init__.py , then you can use from ..bar_dir import bar If the directories aren't Python packages, you can do this by messing around with sys.path , but you shouldn't. You can use the sys and os modules for generalized imports. In foo.py start with the lines import sys import os sys.path.append(os.path.abspath('../bar_dir')) import bar 来源: https://stackoverflow.com/questions/10272879/how-do-i-import-a-python

Python: sharing common code among a family of scripts

不打扰是莪最后的温柔 提交于 2019-11-29 23:03:18
I'm writing a family of Python scripts within a project; each script is within a subdirectory of the project, like so: projectroot | |- subproject1 | | | |- script1.main.py | `- script1.merger.py | |- subproject2 | | | |- script2.main.py | |- script2.matcher.py | `- script2.merger.py | `- subproject3 | |- script3.main.py |- script3.converter.py |- script3.matcher.py `- script3.merger.py Now several of the scripts share some code. The shared code is best considered part of the project itself, and not something I would compile separately and make a library out of, or drop in a sitewide

Best practice for reusing python code [closed]

放肆的年华 提交于 2019-11-29 20:09:55
I have write a python library app(which contains several *.py files). And several of my python projects need to reuse the code in the library app. What's the recommended best practice for reusing python code? Currently I have thought out three options: Copy and paste. This is far away from best practice. It violates the DRY principle.(Don't repeat yourself.) Add the folder of the library app to the environment variable PYTHONPATH: export PYTHONPATH=/path/to/library/app . Then every projects on the same computer can reference the code in the library app. And the folder of the library app to sys

Where to put a configuration file in Python?

a 夏天 提交于 2019-11-29 18:56:55
In development mode, I have the following directory tree : | my_project/ | setup.py | my_project/ | __init__.py | main.py | conf/ | myproject.conf I use ConfigParser to parse the myproject.conf file. In my code, it's easy to load the file with a good path : my_project/conf/myproject.conf The problem is : When I install my project using the setup.py, the configuration file are situated (thanks to setup.py) in the /etc/my_project/myproject.conf and my application in the /usr/lib/python<version>/site-packages/my_project/ . How can I refer my my_project/conf/myproject.conf file in my project in

Creating a secondary site-packages directory (and loading packages from .pth files therein)

我是研究僧i 提交于 2019-11-29 06:10:13
问题 I would like to install some packages into a third-party site-packages directory (beyond the standard system locations). Is there any way to set this up such that .pth files therein are respected? Background: I'm using OS X, virtualenv, and homebrew. There are a few packages (notably wxPython in my case) that do not install nicely through pip into virtualenv. In these cases, there are homebrew packages that work in their stead. Homebrew creates a third site-packages folder in /usr/local/lib

Customize module search path (PYTHONPATH) via pipenv

不打扰是莪最后的温柔 提交于 2019-11-29 03:15:39
I have a Python project consisting of a Jupyter notebook, several scripts in a bin directory and modules in a src directory, with dependencies in a Pipfile : myproject ├── myproject.ipynb ├── Pipfile ├── Pipfile.lock ├── bin │ ├── bar.py │ └── foo.py └── src ├── baz.py └── qux.py The scripts foo.py and bar.py use the standard shebang #!/usr/bin/env python and can be run with pipenv shell : mymachine:myproject myname$ pipenv shell (myproject-U308romt) bash-3.2$ bin/foo.py foo However, I can't easily access the modules in src from the scripts. If I add import src.baz as baz to foo.py , I get:

How do I import a Python script from a sibling directory?

≯℡__Kan透↙ 提交于 2019-11-29 01:30:22
问题 Here is the directory structure: parent_dir/ foo_dir/ foo.py bar_dir/ bar.py How do I import bar.py into foo.py? 回答1: If all occurring directories are Python packages , i.e. they all contain __init__.py , then you can use from ..bar_dir import bar If the directories aren't Python packages, you can do this by messing around with sys.path , but you shouldn't. 回答2: You can use the sys and os modules for generalized imports. In foo.py start with the lines import sys import os sys.path.append(os

How to add something to PYTHONPATH?

坚强是说给别人听的谎言 提交于 2019-11-29 01:24:10
I downloaded a package (called pysolr 2.0.15) to my computer to be used with Haystack. The instructions asks me to add pysolr to my PYTHONPATH. What exactly does that mean? After extracting the pysolr files, I ran the command python setup.py install and that's about it. What did that do and do I need to do anything else? Thanks for the help! The pythonpath tells python were to look for modules, for example you might have written a library that you want to use in several applications and stored it in the path /mylibs/python/ you would then have to add that path to the pythonpath for python to

What to set `SPARK_HOME` to?

耗尽温柔 提交于 2019-11-28 20:26:39
Installed apache-maven-3.3.3, scala 2.11.6, then ran: $ git clone git://github.com/apache/spark.git -b branch-1.4 $ cd spark $ build/mvn -DskipTests clean package Finally: $ git clone https://github.com/apache/incubator-zeppelin $ cd incubator-zeppelin/ $ mvn install -DskipTests Then ran the server: $ bin/zeppelin-daemon.sh start Running a simple notebook beginning with %pyspark , I got an error about py4j not being found. Just did pip install py4j ( ref ). Now I'm getting this error: pyspark is not responding Traceback (most recent call last): File "/tmp/zeppelin_pyspark.py", line 22, in