Cómo añadir a la pythonpath en Windows?


Tengo un directorio que aloja todas mis aplicaciones Django (C:\My_Projects). Quiero agregar este directorio a mi pythonpath para poder llamar a las aplicaciones directamente.

He intentado agregar C:\My_Projects\; a mi variable Path desde la interfaz gráfica de Windows (My Computer > Properties > Advanced System Settings > Environment Variables). Pero todavía no lee el módulo coltrane y genera este error:

Error: Ningún módulo llamado coltrane

Author: cricket_007, 2010-09-13

17 answers

Sabes lo que me ha funcionado muy bien en Windows.

My Computer > Properties > Advanced System Settings > Environment Variables >

Simplemente agregue la ruta como C:\Python27 (o donde quiera que haya instalado python)

O

Luego, bajo variables del sistema, creo una nueva Variable llamada PythonPath. En esta variable tengo C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\other-folders-on-the-path

introduzca la descripción de la imagen aquí

Esta es la mejor manera que ha funcionado para mí que no había encontrado en ninguno de los documentos ofrecidos.

EDITAR: Para aquellos que no son capaces de obtenerlo, Por favor, añadir

C:\Python27;

Junto con él. De lo contrario, nunca funcionará .

 343
Author: darren,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-18 19:46:13

Windows 7 Profesional He modificado la respuesta de @mongoose_za para que sea más fácil cambiar la versión de python:

  1. [Clic derecho] Equipo > Propiedades >Configuración avanzada del Sistema > Variables de entorno
  2. Haga clic en [Nuevo] en "Variable del sistema"
  3. Nombre de la variable: PY_HOME, Valor de la variable: C: \ path\to \ python \ version introduzca la descripción de la imagen aquí
  4. Haga clic en [Aceptar]
  5. Localice la variable del sistema "Path" y haga clic en[Edit]
  6. Añadir lo siguiente a la variable:

    %PY_HOME%; % PY_HOME % \Lib;%PY_HOME%\DLL;%PY_HOME%\Lib\lib-tk; introduzca la descripción de la imagen aquí

  7. Haga clic en [OK] para cerrar todas las ventanas.

Como comprobación final de cordura, abra un símbolo del sistema e ingrese python. Usted debe ver

>python [whatever version you are using]

Si necesita cambiar entre versiones, solo necesita modificar la variable PY_HOME para que apunte al directorio adecuado. Esto es un poco más fácil de administrar si necesita varias versiones de Python instaladas.

 99
Author: Delicia Brummitt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-29 13:55:24

Simplemente agregue la ruta de instalación (ej. C:\Python27\) a la variable PATH en System variables . Luego cierre y abra su línea de comandos y escriba 'python'.

 65
Author: Paulino III,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-07 14:26:21

Desde la línea de comandos de Windows:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

Para establecer el PYTHONPATH permanentemente, agregue la línea a su autoexec.bat. Alternativamente, si edita la variable del sistema a través de las Propiedades del sistema, también se cambiará permanentemente.

 54
Author: Yuval Adam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-13 17:00:31

Estas soluciones funcionan, pero funcionan para su código SOLO en su máquina. Añadiría un par de líneas a su código que se ven así:

import sys
if "C:\\My_Python_Lib" not in sys.path:
    sys.path.append("C:\\My_Python_Lib")

Que debe hacerse cargo de sus problemas

 47
Author: inspectorG4dget,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-13 16:11:38

Añadiendo Python y PythonPath al entorno Windows:

  1. Abra el explorador.
  2. Haga clic con el botón derecho en 'Computer' en el Panel del Árbol de navegación a la izquierda.
  3. Seleccione 'Properties' en la parte inferior del Menú contextual.
  4. Seleccione 'Configuración avanzada del sistema'
  5. Haga clic en 'Variables de entorno...' en la pestaña Avanzado
  6. En el Sistema " Variables':

    1. Añadir

      • PY_HOME

        C:\Python27
        
      • PYTHONPATH

        %PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk;C:\another-library
        
    2. Añadir

      • path

        %PY_HOME%;%PY_HOME%\Scripts\
        
 31
Author: Mr. Polywhirl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-16 12:51:09

La forma más fácil de establecer la ruta en python es : haga clic en inicio > Mi equipo > Propiedades > Configuración avanzada del sistema >Variables de entorno > segundo windows >

introduzca la descripción de la imagen aquí

Seleccione Ruta > Editar > y luego agregar"; C:\Python27\;C:\Python27\Scripts\ "

Enlace :http://docs.python-guide.org/en/latest/starting/install/win/

 18
Author: Bamara Coulibaly,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-18 18:41:03

Necesita agregar a su variable PYTHONPATH en lugar de la variable Windows PATH.

Http://docs.python.org/using/windows.html

 14
Author: Tao,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-13 15:13:00

También puede agregar un archivo .pth que contenga el directorio deseado en su carpeta c:\PythonX.X o en su \site-packages folder, que tiende a ser mi método preferido cuando estoy desarrollando un paquete Python.

Ver aquí para más información.

 12
Author: brentlance,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-05 04:56:18

Para aumentar PYTHONPATH, ejecute regedit y navegue hasta KEY_LOCAL_MACHINE \SOFTWARE\Python\PythonCore y luego seleccione la carpeta para python versión que desea utilizar. Dentro de esta carpeta hay una llamada PythonPath, con una entrada que especifica las rutas donde la instalación predeterminada almacena módulos. Haga clic derecho en PythonPath y elija crear una nueva clave. Es posible que desee nombrar la clave después del proyecto cuyo módulo ubicaciones que especificará; de esta manera, puede compartimentar fácilmente y pista sus modificaciones de ruta.

Gracias

 5
Author: Brajendu Kumar Das,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-13 07:41:54

El python 2.Las rutas X se pueden establecer a partir de algunas de las instrucciones anteriores. Python 3 por defecto se instalará en C:\Users\\AppData\Local\Programs\Python\Python35-32\ Por lo tanto, esta ruta debe agregarse a la variable de ruta en el entorno Windows.

 5
Author: Pavan Ebbadi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-29 00:43:41
import sys
sys.path.append("path/to/Modules")
print sys.path

Esto no persistirá durante los reinicios ni se traducirá a otros archivos. Es sin embargo grande si usted no quiere hacer una modificación permanente a su sistema.

 5
Author: Gajendra D Ambi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-19 10:49:43

Para cualquiera que intente lograr esto con Python 3.3+, el instalador de Windows ahora incluye una opción para agregar python.exe a la ruta de búsqueda del sistema. Lea más en los documentos.

 3
Author: Andreas Bergström,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-04 09:01:17

En Python 3.4 en windows funcionó cuando lo agregué a variable de entorno PATH en lugar de PYTHONPATH. Como si ha instalado Python 3.4 en D:\Programming\Python34 luego agregue esto al final de su variable de entorno PATH

;D:\Programming\Python34

Cierre y vuelva a abrir el símbolo del sistema y ejecute 'python'. Abrirá la shell de Python. Esto también solucionó mi problema Sublime 3 de 'python no se reconoce como un comando interno o externo'.

 3
Author: Octane,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-29 21:05:20

Esta variable PYTHONPATH debe configurarse para ArcPY cuando se instale ArcGIS Desktop.

PYTHONPATH=C:\arcgis\bin (su ArcGIS home bin)

Por alguna razón nunca se estableció cuando utilicé el instalador en un sistema Windows 7 de 32 bits.

 2
Author: Dan Randolph,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-05 04:57:05

Tal vez un poco tarde, pero así es como se agrega la ruta a las variables de entorno de Windows.

  1. Vaya a la pestaña Variables de entorno, haga esto presionando la tecla Windows + Pausa inter.

  2. Vaya a Configuración avanzada del sistema.

  3. Haga clic en Variables de entorno.

  4. En la ventana inferior busque el valor 'Path'.

  5. Seleccione

  6. Haga Clic en Editar

  7. Al final de la línea añadir su carpeta de instalación y la ruta a la carpeta 'Scripts'.

  8. Haga clic en aceptar, aceptar, etc.

Ha terminado, ingrese cmd y escriba python desde cualquier ubicación de su unidad, debe ingresar el programa Python.

Ejemplo con mi pc (tengo Python34)

EXISTING_LINES;C:\Python34;C:\Python34\Scripts\

Espero que ayude.

Saludos desde Bogotá

 1
Author: sandatomo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-28 19:58:46

Estas respuestas son tan malas. El instalador tiene una opción secreta. Haga clic de nuevo en el instalador, desinstálelo y vuelva a instalarlo.

introduzca la descripción de la imagen aquí

 -3
Author: Eddie,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-01 21:56:05