@@ -29,12 +29,6 @@ The following functions can be safely called before Python is initialized:
29
29
* :c:func: `PyMem_SetAllocator `
30
30
* :c:func: `PyMem_SetupDebugHooks `
31
31
* :c:func: `PyObject_SetArenaAllocator `
32
- * :c:func: `Py_SetPath `
33
- * :c:func: `Py_SetProgramName `
34
- * :c:func: `Py_SetPythonHome `
35
- * :c:func: `Py_SetStandardStreamEncoding `
36
- * :c:func: `PySys_AddWarnOption `
37
- * :c:func: `PySys_AddXOption `
38
32
* :c:func: `PySys_ResetWarnOptions `
39
33
40
34
* Informative functions:
@@ -332,16 +326,13 @@ Initializing and finalizing the interpreter
332
326
.. c :function :: void Py_Initialize ()
333
327
334
328
.. index::
335
- single: Py_SetProgramName()
336
329
single: PyEval_InitThreads()
337
330
single: modules (in module sys)
338
331
single: path (in module sys)
339
332
pair: module; builtins
340
333
pair: module; __main__
341
334
pair: module; sys
342
335
triple: module; search; path
343
- single: PySys_SetArgv()
344
- single: PySys_SetArgvEx()
345
336
single: Py_FinalizeEx()
346
337
347
338
Initialize the Python interpreter. In an application embedding Python,
@@ -352,7 +343,9 @@ Initializing and finalizing the interpreter
352
343
the table of loaded modules (``sys.modules ``), and creates the fundamental
353
344
modules :mod: `builtins `, :mod: `__main__ ` and :mod: `sys `. It also initializes
354
345
the module search path (``sys.path ``). It does not set ``sys.argv ``; use
355
- :c:func: `PySys_SetArgvEx ` for that. This is a no-op when called for a second time
346
+ the new :c:type: `PyConfig ` API of the :ref: `Python Initialization
347
+ Configuration <init-config>` for that. This is a no-op when called for a
348
+ second time
356
349
(without calling :c:func: `Py_FinalizeEx ` first). There is no return value; it is a
357
350
fatal error if the initialization fails.
358
351
@@ -425,76 +418,9 @@ Process-wide parameters
425
418
=======================
426
419
427
420
428
- .. c:function:: int Py_SetStandardStreamEncoding(const char *encoding, const char *errors)
429
-
430
- .. index ::
431
- single: Py_Initialize()
432
- single: main()
433
- triple: stdin; stdout; sdterr
434
-
435
- This API is kept for backward compatibility: setting
436
- :c:member: `PyConfig.stdio_encoding ` and :c:member: `PyConfig.stdio_errors `
437
- should be used instead, see :ref: `Python Initialization Configuration
438
- <init-config>`.
439
-
440
- This function should be called before :c:func: `Py_Initialize `, if it is
441
- called at all. It specifies which encoding and error handling to use
442
- with standard IO, with the same meanings as in :func: `str.encode `.
443
-
444
- It overrides :envvar: `PYTHONIOENCODING ` values, and allows embedding code
445
- to control IO encoding when the environment variable does not work.
446
-
447
- *encoding * and/or *errors * may be ``NULL `` to use
448
- :envvar: `PYTHONIOENCODING ` and/or default values (depending on other
449
- settings).
450
-
451
- Note that :data:`sys.stderr` always uses the "backslashreplace" error
452
- handler, regardless of this (or any other) setting.
453
-
454
- If :c:func:`Py_FinalizeEx` is called, this function will need to be called
455
- again in order to affect subsequent calls to :c:func:`Py_Initialize`.
456
-
457
- Returns ``0`` if successful, a nonzero value on error (e.g. calling after the
458
- interpreter has already been initialized).
459
-
460
- .. versionadded:: 3.4
461
-
462
- .. deprecated:: 3.11
463
-
464
-
465
- .. c:function:: void Py_SetProgramName(const wchar_t *name)
466
-
467
- .. index ::
468
- single: Py_Initialize()
469
- single: main()
470
- single: Py_GetPath()
471
-
472
- This API is kept for backward compatibility: setting
473
- :c:member: `PyConfig.program_name ` should be used instead, see :ref: `Python
474
- Initialization Configuration <init-config>`.
475
-
476
- This function should be called before :c:func: `Py_Initialize ` is called for
477
- the first time, if it is called at all. It tells the interpreter the value
478
- of the ``argv[0] `` argument to the :c:func: `main ` function of the program
479
- (converted to wide characters).
480
- This is used by :c:func:`Py_GetPath` and some other functions below to find
481
- the Python run-time libraries relative to the interpreter executable. The
482
- default value is ``'python'``. The argument should point to a
483
- zero-terminated wide character string in static storage whose contents will not
484
- change for the duration of the program's execution. No code in the Python
485
- interpreter will change the contents of this storage.
486
-
487
- Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
488
- :c:expr:`wchar_*` string.
489
-
490
- .. deprecated:: 3.11
491
-
492
-
493
421
.. c:function:: wchar* Py_GetProgramName()
494
422
495
- .. index:: single: Py_SetProgramName()
496
-
497
- Return the program name set with :c:func:`Py_SetProgramName`, or the default.
423
+ Return the program name set with :c:member:`PyConfig.program_name`, or the default.
498
424
The returned string points into static storage; the caller should not modify its
499
425
value.
500
426
@@ -509,7 +435,7 @@ Process-wide parameters
509
435
510
436
Return the *prefix* for installed platform-independent files. This is derived
511
437
through a number of complicated rules from the program name set with
512
- :c:func:`Py_SetProgramName ` and some environment variables; for example, if the
438
+ :c:member:`PyConfig.program_name ` and some environment variables; for example, if the
513
439
program name is ``'/usr/local/bin/python' ``, the prefix is ``'/usr/local' ``. The
514
440
returned string points into static storage; the caller should not modify its
515
441
value. This corresponds to the :makevar: `prefix ` variable in the top-level
@@ -528,7 +454,7 @@ Process-wide parameters
528
454
529
455
Return the *exec-prefix* for installed platform-*dependent* files. This is
530
456
derived through a number of complicated rules from the program name set with
531
- :c:func:`Py_SetProgramName ` and some environment variables; for example, if the
457
+ :c:member:`PyConfig.program_name ` and some environment variables; for example, if the
532
458
program name is ``'/usr/local/bin/python' ``, the exec-prefix is
533
459
``'/usr/local' ``. The returned string points into static storage; the caller
534
460
should not modify its value. This corresponds to the :makevar: `exec_prefix `
@@ -568,12 +494,11 @@ Process-wide parameters
568
494
.. c :function :: wchar_t * Py_GetProgramFullPath ()
569
495
570
496
.. index::
571
- single: Py_SetProgramName()
572
497
single: executable (in module sys)
573
498
574
499
Return the full program name of the Python executable; this is computed as a
575
500
side-effect of deriving the default module search path from the program name
576
- (set by :c:func: ` Py_SetProgramName ` above ). The returned string points into
501
+ (set by :c:member: ` PyConfig.program_name ` ). The returned string points into
577
502
static storage; the caller should not modify its value. The value is available
578
503
to Python code as ``sys.executable ``.
579
504
@@ -589,10 +514,9 @@ Process-wide parameters
589
514
.. index::
590
515
triple: module; search; path
591
516
single: path (in module sys)
592
- single: Py_SetPath()
593
517
594
518
Return the default module search path; this is computed from the program name
595
- (set by :c:func: ` Py_SetProgramName ` above ) and some environment variables.
519
+ (set by :c:member: ` PyConfig.program_name ` ) and some environment variables.
596
520
The returned string consists of a series of directory names separated by a
597
521
platform dependent delimiter character. The delimiter character is ``':' ``
598
522
on Unix and macOS, ``';' `` on Windows. The returned string points into
@@ -610,44 +534,6 @@ Process-wide parameters
610
534
It now returns ``NULL `` if called before :c:func: `Py_Initialize `.
611
535
612
536
613
- .. c :function :: void Py_SetPath (const wchar_t *)
614
-
615
- .. index ::
616
- triple: module; search; path
617
- single: path (in module sys)
618
- single: Py_GetPath()
619
-
620
- This API is kept for backward compatibility: setting
621
- :c:member:`PyConfig.module_search_paths` and
622
- :c:member:`PyConfig.module_search_paths_set` should be used instead, see
623
- :ref:`Python Initialization Configuration <init-config>`.
624
-
625
- Set the default module search path. If this function is called before
626
- :c:func:`Py_Initialize`, then :c:func:`Py_GetPath` won't attempt to compute a
627
- default search path but uses the one provided instead. This is useful if
628
- Python is embedded by an application that has full knowledge of the location
629
- of all modules. The path components should be separated by the platform
630
- dependent delimiter character, which is ``':'`` on Unix and macOS, ``';' ``
631
- on Windows.
632
-
633
- This also causes :data:`sys.executable` to be set to the program
634
- full path (see :c:func:`Py_GetProgramFullPath`) and for :data:`sys.prefix` and
635
- :data:`sys.exec_prefix` to be empty. It is up to the caller to modify these
636
- if required after calling :c:func:`Py_Initialize`.
637
-
638
- Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
639
- :c:expr:`wchar_*` string.
640
-
641
- The path argument is copied internally, so the caller may free it after the
642
- call completes.
643
-
644
- .. versionchanged:: 3.8
645
- The program full path is now used for :data:`sys.executable`, instead
646
- of the program name.
647
-
648
- .. deprecated:: 3.11
649
-
650
-
651
537
.. c :function :: const char * Py_GetVersion ()
652
538
653
539
Return the version of this Python interpreter. This is a string that looks
@@ -718,110 +604,10 @@ Process-wide parameters
718
604
``sys.version``.
719
605
720
606
721
- .. c:function:: void PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
722
-
723
- .. index::
724
- single: main()
725
- single: Py_FatalError()
726
- single: argv (in module sys)
727
-
728
- This API is kept for backward compatibility: setting
729
- :c:member:`PyConfig.argv`, :c:member:`PyConfig.parse_argv` and
730
- :c:member:`PyConfig.safe_path` should be used instead, see :ref:`Python
731
- Initialization Configuration <init-config>`.
732
-
733
- Set :data:`sys.argv` based on *argc* and *argv*. These parameters are
734
- similar to those passed to the program' s :c:func:`main` function with the
735
- difference that the first entry should refer to the script file to be
736
- executed rather than the executable hosting the Python interpreter. If there
737
- isn't a script that will be run, the first entry in *argv * can be an empty
738
- string. If this function fails to initialize :data: `sys.argv `, a fatal
739
- condition is signalled using :c:func: `Py_FatalError `.
740
-
741
- If *updatepath * is zero, this is all the function does. If *updatepath *
742
- is non-zero, the function also modifies :data: `sys.path ` according to the
743
- following algorithm:
744
-
745
- - If the name of an existing script is passed in ``argv[0] ``, the absolute
746
- path of the directory where the script is located is prepended to
747
- :data: `sys.path `.
748
- - Otherwise (that is, if *argc * is ``0 `` or ``argv[0] `` doesn't point
749
- to an existing file name), an empty string is prepended to
750
- :data: `sys.path `, which is the same as prepending the current working
751
- directory (``"." ``).
752
-
753
- Use :c:func: `Py_DecodeLocale ` to decode a bytes string to get a
754
- :c:expr: `wchar_* ` string.
755
-
756
- See also :c:member: `PyConfig.orig_argv ` and :c:member: `PyConfig.argv `
757
- members of the :ref: `Python Initialization Configuration <init-config >`.
758
-
759
- .. note ::
760
- It is recommended that applications embedding the Python interpreter
761
- for purposes other than executing a single script pass ``0 `` as *updatepath *,
762
- and update :data: `sys.path ` themselves if desired.
763
- See `CVE-2008-5983 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983 >`_.
764
-
765
- On versions before 3.1.3, you can achieve the same effect by manually
766
- popping the first :data: `sys.path ` element after having called
767
- :c:func: `PySys_SetArgv `, for example using::
768
-
769
- PyRun_SimpleString("import sys; sys.path.pop(0)\n");
770
-
771
- .. versionadded :: 3.1.3
772
-
773
- .. XXX impl. doesn't seem consistent in allowing ``0``/``NULL`` for the params;
774
- check w/ Guido.
775
-
776
- .. deprecated :: 3.11
777
-
778
-
779
- .. c :function :: void PySys_SetArgv (int argc, wchar_t **argv)
780
-
781
- This API is kept for backward compatibility: setting
782
- :c:member: `PyConfig.argv ` and :c:member: `PyConfig.parse_argv ` should be used
783
- instead, see :ref: `Python Initialization Configuration <init-config >`.
784
-
785
- This function works like :c:func: `PySys_SetArgvEx ` with *updatepath * set
786
- to ``1 `` unless the :program: `python ` interpreter was started with the
787
- :option: `-I `.
788
-
789
- Use :c:func: `Py_DecodeLocale ` to decode a bytes string to get a
790
- :c:expr: `wchar_* ` string.
791
-
792
- See also :c:member: `PyConfig.orig_argv ` and :c:member: `PyConfig.argv `
793
- members of the :ref: `Python Initialization Configuration <init-config >`.
794
-
795
- .. versionchanged :: 3.4 The *updatepath* value depends on :option:`-I`.
796
-
797
- .. deprecated :: 3.11
798
-
799
-
800
- .. c :function :: void Py_SetPythonHome (const wchar_t *home)
801
-
802
- This API is kept for backward compatibility: setting
803
- :c:member: `PyConfig.home ` should be used instead, see :ref: `Python
804
- Initialization Configuration <init-config>`.
805
-
806
- Set the default "home" directory, that is, the location of the standard
807
- Python libraries. See :envvar: `PYTHONHOME ` for the meaning of the
808
- argument string.
809
-
810
- The argument should point to a zero-terminated character string in static
811
- storage whose contents will not change for the duration of the program's
812
- execution. No code in the Python interpreter will change the contents of
813
- this storage.
814
-
815
- Use :c:func: `Py_DecodeLocale ` to decode a bytes string to get a
816
- :c:expr: `wchar_* ` string.
817
-
818
- .. deprecated :: 3.11
819
-
820
-
821
607
.. c:function:: wchar_t* Py_GetPythonHome()
822
608
823
- Return the default "home", that is, the value set by a previous call to
824
- :c:func:`Py_SetPythonHome `, or the value of the :envvar:`PYTHONHOME`
609
+ Return the default " home" , that is, the value set by
610
+ :c:member:`PyConfig.home `, or the value of the :envvar:`PYTHONHOME`
825
611
environment variable if it is set.
826
612
827
613
This function should not be called before :c:func:`Py_Initialize`, otherwise
0 commit comments