pythonpath

Add to python path mac os x

狂风中的少年 提交于 2019-11-26 19:36:59
I thought import sys sys.path.append("/home/me/mydir") is appending a dir to my pythonpath if I print sys.path my dir is in there. Then I open a new command and it is not there anymore. But somehow Python cant import modules I saved in that dir. What Am I doing wrong? I read .profile or .bash_profile will do the trick. Do I have to add: PATH="/Me//Documents/mydir:$PYTHONPATH" export PATH To make it work? Matthew Flaschen Modifications to sys.path only apply for the life of that Python interpreter. If you want to do it permanently you need to modify the PYTHONPATH environment variable:

How does python find a module file if the import statement only contains the filename?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 18:47:17
Everywhere I see Python code importing modules using import sys or import mymodule How does the interpreter find the correct file if no directory or path is provided? dm03514 http://docs.python.org/3/tutorial/modules.html#the-module-search-path 6.1.2. The Module Search Path When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path . sys.path is initialized from these locations: The directory containing the input script (or the current

Why use sys.path.append(path) instead of sys.path.insert(1, path)?

本小妞迷上赌 提交于 2019-11-26 18:39:55
Edit: based on a Ulf Rompe's comment, it is important you use "1" instead of "0" , otherwise you will break sys.path . I have been doing python for quite a while now (over a year), and I am always confused as to why people recommend you use sys.path.append() instead of sys.path.insert() . Let me demonstrate. Let's say I am working on a module named PyWorkbooks (that is installed on my computer), but I am simultaneously working on a different module (let's say PyJob) that incorporates PyWorkbooks. As I'm working on PyJob I find errors in PyWorkbooks that I am correcting, so I would like to

How to configure custom PYTHONPATH with VM and PyCharm?

故事扮演 提交于 2019-11-26 17:19:13
I am using IntelliJ with the Python plugin and the Remote Interpreter feature to communicate with my Vagrant VM. It sets up the remote interpreter correctly to use my VM's interpreter. But, I use a custom PYTHONPATH in my VM, and I would like IntelliJ to recognize that path and include the modules in that path when developing. How do I configure IntelliJ/PyCharm's remote interpreter to use a custom PYTHONPATH on the VM? For PyCharm 5 (or 2016.1), you can: select Preferences > Project Interpreter to the right of interpreter selector there is a "..." button, click it select "more..." pop up a

PYTHONPATH vs. sys.path

我怕爱的太早我们不能终老 提交于 2019-11-26 17:09:26
Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory. We have a Python project with a typical directory structure: Project setup.py package __init__.py lib.py script.py In script.py, we need to do import package.lib . When the package is installed in site-packages, script.py can find package.lib . When working from a user directory, however, something else needs to be done. My solution is to set my PYTHONPATH to include "~/Project". Another developer wants to put this line of code

Python - add PYTHONPATH during command line module run

戏子无情 提交于 2019-11-26 16:06:36
I want to run: python somescript.py somecommand But, when I run this I need PYTHONPATH to include a certain directory. I can't just add it to my environment variables because the directory I want to add changes based on what project I'm running. Is there a way to alter PYTHONPATH while running a script? Note: I don't even have a PYTHONPATH variable, so I don't need to worry about appending to it vs overriding it during running of this script. For Mac/Linux; PYTHONPATH=/foo/bar/baz python somescript.py somecommand For Windows, setup a wrapper pythonpath.bat ; @ECHO OFF setlocal set PYTHONPATH=

Import Error: No module named django

别等时光非礼了梦想. 提交于 2019-11-26 14:07:04
问题 I am using centos linux. I had python 2.6 with django and now i upgraded to python 2.7. Python 2.6 is located in /usr/lib/python2.6. Python 2.7 is located in /usr/local/lib/python2.7. They both have site-packages directory and they both contain django 1.2. If i run python i get the 2.7 version. My problem is that if try to import django i get ImportError: No module named django I am not sure where is my PYTHONPATH defined and if this is what i need to change. anyone ? i ended up making a

Why use sys.path.append(path) instead of sys.path.insert(1, path)?

放肆的年华 提交于 2019-11-26 08:55:34
问题 Edit: based on a Ulf Rompe\'s comment, it is important you use \"1\" instead of \"0\" , otherwise you will break sys.path. I have been doing python for quite a while now (over a year), and I am always confused as to why people recommend you use sys.path.append() instead of sys.path.insert() . Let me demonstrate. Let\'s say I am working on a module named PyWorkbooks (that is installed on my computer), but I am simultaneously working on a different module (let\'s say PyJob) that incorporates

django import error - No module named core.management

≯℡__Kan透↙ 提交于 2019-11-26 07:59:08
问题 Ok, I see plenty of these errors around. I have tried everything I know to do and have yet to figure this out. I am working on a development server running python 2.5 and Django 1.3. Django 1.3 was installed using python setup.py install after unpacking the tar.gz download. All works well, I seldom have the need to run manage.py but am trying to use the new staticfiles app and am running into problems. python manage.py collectstatic Traceback (most recent call last): File \"manage.py\", line

Add to python path mac os x

可紊 提交于 2019-11-26 07:20:47
问题 I thought import sys sys.path.append(\"/home/me/mydir\") is appending a dir to my pythonpath if I print sys.path my dir is in there. Then I open a new command and it is not there anymore. But somehow Python cant import modules I saved in that dir. What Am I doing wrong? I read .profile or .bash_profile will do the trick. Do I have to add: PATH=\"/Me//Documents/mydir:$PYTHONPATH\" export PATH To make it work? 回答1: Modifications to sys.path only apply for the life of that Python interpreter. If