python - importing from venv folder with same file name -


I am using Python with a redis library with virtualenv.

I have a file that means Redis.py on which the import is low; Import the class redis extension (extension): def __init __ (self, config): print redis class Redis (mask): Pass

However, It seems that it imports itself, even if the venv folder is active.

/ P> < / Div>

BTW, your requirement is unusual and what I show here is the type of hack. It would be better if you can manage to manage your dragon script / module in a more appropriate name.

By default, Python imports the number of different paths, one of them is current. <> & gt; & Gt; & Gt; Import OS & gt; & Gt; & Gt; Os.sys.path [',' / home / javl / envs / so / bin ',' /home/javl/Envs/so/lib/python2.7 ',' / home / javl / envs / so / lib / Python2.7 / plat-x86_64-linux-gnu ',' /home/javl/Envs/so/lib/python2.7/lib-tk ',' /home/javl/Envs/so/lib/python2.7 / Lib-old ',' /home/javl/Envs/so/lib/python2.7/lib-dynload ',' /usr/lib/python2.7 ',' /usr/lib/python2.7/plat-x86_64 -linux-gnu ',' /usr/lib/python2.7/lib-tk ',' /home/javl/Envs/so/local/lib/python2.7/site-packages ',' / home / javl / Envs / so / lib / python2.7 / site-packages ',' /home/javl/Envs/so/local/lib/python2.7/site-packages/IPython/extensions ',' / home / javl / / Ipython ']

As you see, the first item is "". This means "remove this directory":

  & gt; & Gt; & Gt; Os.sys.path.remove ("") & gt; & Gt; & Gt; Os.sys.path ['/ home / javl / envs / so / bin', '/home/javl/Envs/so/lib/python2.7', '/ home / javl / envs / so / lib / python2 7 / Plat-x86_64-linux-gnu ',' /home/javl/Envs/so/lib/python2.7/lib-tk ',' /home/javl/Envs/so/lib/python2.7/lib-sold ',' / Home / jwl / ANVS / SO / Lib / Python 2.7 / lib-dynamicload ',' / url / lib / python2.7 ',' /usr/lib/python2.7/plat-x86_64-linux -gnu ',' /usr/lib/python2.7/lib-tk ',' /home/javl/Envs/so/local/lib/python2.7/site-packages ',' / home / javl / envs / hence / Lib / python2.7 / site-packages', '/home/javl/Envs/so/local/lib/python2.7/site-packages/IPython/extensions',' /home/javl/.ipython '] & gt; ; & Gt; & Gt; Import re-code   

If we want to talk back to the original order, then we can do the following:

  & gt; & Gt; & Gt; Os.sys.path.insert (0, "")   

You can change this amendment to your redis.py

  Os .sys.path.remove ("") import redis os.sys.path.insert (0, "") class redisExtension (extension): def __init __ (self, config): print redis class redis (mask): pass < / Code>   

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -