How to add a colon directory in PYTHONPATH?

The problem is simple:

Using bash, I want to add a directory to my PYTHONPATH for the convenience of script execution. Unfortunately, the directory that I want to use is: in it. Therefore, I try each of the following

export PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.com:3344/
export PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.com\:3344/
export PYTHONPATH=${PYTHONPATH}:"/home/shane/mywebsite.com:3344/"

None of these works. Each time a path is created as two separate directories on a path in python. My question is: is it possible to do this for bash? If so, what syntax is required?

+5
source share
5 answers

The problem is not in bash. Your environment variable must be correctly set, complete with the symbol :.

Python PYTHONPATH. , PATH, , escape- , : . Python.

, , , - , .

+8

, :

export PYTHONPATH=${PYTHONPATH}:"/home/shane/mywebsite.com\:3344/"

, ":" . ":" .

$ echo "foo:" 
foo:
$ echo \:foo
:foo
$ echo ":foo"
:foo
$ echo "\:foo"
\:foo

, python, .

+2

, , , , , Linux, "" PYTHONPATH :

ln -s /home/shane/mywebsite.com\:3344 /home/shane/mywebsite.3344
export PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.3344
+1

, , , - , , PYTHONPATH.

0

URL- . URL- , python python . URL- PYTHONPATH.

Despite this, some people may find themselves in this issue due to the following:

On the Windows paths there are disk pointers followed by a colon, for example C:/Python27/lib. In bash on Windows, you can add several paths to PYTHONPATH with a semicolon, like this:

$ export PYTHONPATH="C:\MYPATH1;C:\MYPATH2"
$ python -i
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'C:\\MYPATH1', 'C:\\MYPATH2', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin']
0
source

All Articles