pythonpath

Best practice for reusing python code [closed]

我的梦境 提交于 2019-11-28 15:58:50
问题 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

Where to put a configuration file in Python?

怎甘沉沦 提交于 2019-11-28 14:09:37
问题 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>

Pyspark append executor environment variable

两盒软妹~` 提交于 2019-11-28 10:24:21
Is it possible to append a value to the PYTHONPATH of a worker in spark? I know it is possible to go to each worker node, configure spark-env.sh file and do it, but I want a more flexible approach I am trying to use setExecutorEnv method, but with no success conf = SparkConf().setMaster("spark://192.168.10.11:7077")\ .setAppName(''myname')\ .set("spark.cassandra.connection.host", "192.168.10.11") / .setExecutorEnv('PYTHONPATH', '$PYTHONPATH:/custom_dir_that_I_want_to_append/') It creates a pythonpath env.variable on each executor, force it to be lower_case, and does not interprets $PYTHONPATH

Python : How to access file from different directory

删除回忆录丶 提交于 2019-11-28 09:03:37
问题 I have the following project structure SampleProject com python example source utils ConfigManager.py conf constants.cfg How to access constants.cfg from ConfigManager.py. I have a limitation I can not give full path(absolute path) of constants.cfg because if I run in different PC it should work with out any modification Also if I represent something like below, I can access the file. But I don't want to give back slash every time filename = ..\\..\\..\\..\\..\\..\\constants.cfg` Currently I

sys.path different in Jupyter and Python - how to import own modules in Jupyter?

谁说我不能喝 提交于 2019-11-28 05:41:56
In Jupyter my own little module is not loaded but in python/bpython is everything is fine. When typing import sys print(sys.path) the path to my module will not in show in Jupyter but in python/bpython it is still there. I am using: PYTHONPATH in .bashrc to include my module, Jupyter and bpython inside a virtualenv. The most similar questions is this Cannot import modules in jupyter notebook; wrong sys.path How to configure Jupyter to load my modules automagically? Here is what I do on my projects in jupyter notebook, import sys sys.path.append("../") # go to parent dir from customFunctions

set pythonpath before import statements

风流意气都作罢 提交于 2019-11-28 04:38:15
My code is: import scriptlib.abc import scriptlib.xyz def foo(): ... some operations but the scriptlib is in some other directory, so I will have to include that directory in environment variable "PYTHONPATH". Is there anyway in which I can first add the scriptlib directory in environment variable "PYTHONPATH" before import statement getting executed like : import sys sys.path.append('/mypath/scriptlib') import scriptlib.abc import scriptlib.xyz def foo(): ... some operations If so, is the value only for that command prompt or is it global ? Thanks in advance This will add a path to your

Effect of using sys.path.insert(0, path) and sys.path(append) when loading modules

只愿长相守 提交于 2019-11-28 04:07:43
I was recently having a problem with a python ImportError, where the module was found when running on my local computer but not found on the CI server. I solved this problem by swapping sys.path.append(path) in my script with sys.path.insert(0, path) where path is the string module location. Since this is my module and not an installed package ( related question ), why does the order of paths fix this problem? Because python checks in the directories in sequential order starting at the first directory in sys.path list, till it find the .py file it was looking for. Ideally, the current

Python Pythonpath Modules install

跟風遠走 提交于 2019-11-28 01:28:08
问题 I am kind of annoyed by the installation of modules in python and had a lot of trouble with it, so it would be fantastic to find a good solution for it. Here are my issues: PYTHONPATH: How can I tell easy_install/Python where to install my packages? Even though I put: /Library/Python/2.6/site-packages in my .bash_profile With: PYTHONPATH="/Library/Python/2.6/site-packages" export PYTHONPATH It wont import packages I have there. On the other site everything I put into: /Library/Frameworks

Why is my Python 'sys.path' different for each tool I use to run my code?

心不动则不痛 提交于 2019-11-27 21:56:12
问题 I'm confused about the rules used to construct my Python sys.path . I understand that the fist entry will be "the directory containing the script that was used to invoke the Python interpreter", or an empty string if Python was invoked interactively, and that the last entires will be entries based on the installation of Python. But I'm confused about what's going on between these two sets of entries, in particular, how they relate to my PYTHONPATH. When I (A) execute a script that prints out

Python: select one of multiple installed module versions

百般思念 提交于 2019-11-27 19:22:15
On my system, I have several modules installed multiple times. To give an example, numpy 1.6.1 is installed in the standard path at /usr/lib/python2.7/dist-packages , and I have an updated version of numpy 1.8.0 installed at /local/python/lib/python2.7/site-packages/ . The reason I cannot simply remove the old version is that I do not have permissions to change anything on my work computer. I however need to use the new numpy version. I have added /local/python/lib/python2.7/site-packages/ to my PYTHONPATH . Unfortunately, this does not help, since /usr/lib/python2.7/dist-packages is inserted