How to use virtual envs inside PyScripter?

468 views
Skip to first unread message

João Matos

unread,
Oct 28, 2017, 8:41:02 PM10/28/17
to PyScripter
Hello,

Is it possible to use venvs with PyScripter?
Couldn't find anything about it in the manual.

Best regards,

JM

PyScripter

unread,
Oct 29, 2017, 7:12:32 PM10/29/17
to PyScripter
I was not sure so I created a venv and played  with it.  The only difference is the python path.  Here is what it looks like with venv.

['', 'C:\\Temp\\testenv\\Scripts\\python36.zip', 'C:\\Program Files\\Python36\\DLLs', 'C:\\Program Files\\Python36\\lib', 'C:\\Program Files\\Python36', 'C:\\Temp\\testenv', 'C:\\Temp\\testenv\\lib\\site-packages', 'C:\\Program Files\\Python36\\lib\\site-packages']

C:\\Temp\\testenv is the path of my created virtual environment.   C:\\Temp\\testenv\\lib\\site-packages comes before 'C:\\Program Files\\Python36\\lib\\site-packages'.

To have the same effect with Pyscripter you can modify the path similarly using Tools Python path.   Please not that the change in the path is not saved for the next PyScripter session.  For a longer term modification of the path you can select in pyscripter Tools, Edit Startup scripts and add code to python_init.py to modify the python path to the desired one.

João Matos

unread,
Oct 30, 2017, 7:12:12 AM10/30/17
to pyscr...@googlegroups.com, PyScripter
Hello,

That would be a pain because I have several venvs (one for each project).

I added the vens paths to the project Python Path, but PyScripter still launched the main Python interpreter instead of the one in the project Python path.
Is it possible to fix it to PyScripter obeys the project Python path? This would allow PyScripter to work with as many venvs as needed.

One other thing I noticed is that the lines added to the project Python path do appear first on sys.path (which is correct), but appear in the inverse order. Is there a reason why this is?

One final question: How do I close a project?

Thanks,

JM
--
You received this message because you are subscribed to a topic in the Google Groups "PyScripter" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyscripter/T4w1IAzmgT0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyscripter+...@googlegroups.com.
To post to this group, send email to pyscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/pyscripter.
For more options, visit https://groups.google.com/d/optout.

PyScripter

unread,
Oct 30, 2017, 4:32:56 PM10/30/17
to PyScripter
The project python path is appended to the python path, so this would not solve the problem.  The venv site-
packages path has to appear before (or instead of) the standard python site-packages path.  I don't think is such a major issue to change or add one entry in the python path every time you wan to switch venv.  The Python path tool makes this quite easy.

Regarding your second question, to close an open project you just press the New project button or the Open project button.  If the existing project has been modified, you will be prompted to save it before proceeding with the chosen action.


João Matos

unread,
Oct 30, 2017, 5:27:00 PM10/30/17
to pyscr...@googlegroups.com, PyScripter
Hello,

How about a simple command line option to make PyScripter use the existing Path and PythonPath (eg. --existingpaths)?
That way we would call venv <name_of_venv> on the command line as usual and then would just call pyscripter --existingpaths.
There already exists something similar (--pythondllpath= command line option).

That is something (New project option to close an existing one) that doesn't seem obvious to me.
May I suggest a Close project option (that could even do the same as the New project option, but at least would be the obvious choice when we are looking to close the existing one).


Best regards,

JM

João Matos

unread,
Oct 31, 2017, 10:38:57 AM10/31/17
to pyscr...@googlegroups.com, PyScripter
Hello,

While I wait that you consider adding my suggestion to allow PyScripter to work "out of the box" with venvs, I think I found a workaround for now.

I'll explain it here so that anyone trying the same thing may use it. Maybe you can add it to the FAQ.

1. Add PyScripter installation directory (eg. c:\program files (x86)\pyscripter) to the DOS Path env var.
2. Open activate.bat (under the scripts dir in your venv) using notepad and at the very end add the following line
doskey pys=set "PYTHONHOME=%VIRTUAL_ENV%" $T pyscripter --pythondllpath %VIRTUAL_ENV%\scripts

or if you have a PyScripter project with the same name, like me, add this instead
doskey pys=set "PYTHONHOME=%VIRTUAL_ENV%" $T pyscripter --python35 --pythondllpath "%VIRTUAL_ENV%\scripts" --project=%VENV%.psproj

3. When inside a venv just execute pys and PyScripter should open and use your venv paths.

Notes:
The --python35 option must be changed to be correct with your Python version. Use pyscripter /? to check possible options.
I use virtualenvwrapper-win instead of just venv, but this should work with venv with few if any modifications.


This workaround has the disadvantage that before changing venv one must close PyScripter, change venv and then execute a new PyScripter using pys, but I can live with that.



Best regards,

JM


On 30-10-2017 20:32, PyScripter wrote:

João Matos

unread,
Oct 31, 2017, 10:46:21 AM10/31/17
to pyscr...@googlegroups.com, PyScripter
Hello,

Forgot to say that this only works for the internal Python engine.

If I try to use any of the Remotes or the External, they all return the same error.
"Error in creating the remote interpreter: System error. Code: 2."


Best regards,

JM


On 30-10-2017 20:32, PyScripter wrote:

João Matos

unread,
Oct 31, 2017, 10:56:35 AM10/31/17
to pyscr...@googlegroups.com, PyScripter
Hello,

Please consider adding the option "Initially expanded" to
Tools\Options\IDE Options\Project Explorer (it already exists for Code
Explorer).
I would like to be able to have my projects open always collapsed, like
the Code Explorer.

Best regards,

JM

João Matos

unread,
Oct 31, 2017, 11:28:15 AM10/31/17
to pyscr...@googlegroups.com, PyScripter
Hello,

Please consider allowing  $[ActiveDoc-Dir] in items on [Find in Files
Options\DirectoryList] of PyScripter.ini.

Best regards,

JM

João Matos

unread,
Oct 31, 2017, 11:46:39 AM10/31/17
to pyscr...@googlegroups.com, PyScripter
Hello,

I found a strange behaviour in Find in Files.
If I do a Find in Files Search using "search in directories" it shows
the correct results, but if I do the same search using Project files
(the project files are the same files *.py and the same path), it shows
the results in a different way.
I enclosed 2 print-screens for you to see the difference with the
respetive print-screens of the selected search options and project files.

Best regards,

JM

ProjectFiles.png
ProjectFiles2.png
SearchDirectories.png
SearchDirectoriesResults.png
SearchProjectFiles.png
SearchProjectFilesResults.png

PyScripter

unread,
Oct 31, 2017, 4:11:11 PM10/31/17
to PyScripter
For feature requests or bug fixes, please create an issue at https://github.com/pyscripter/pyscripter.

João Matos

unread,
Nov 2, 2017, 5:50:58 AM11/2/17
to pyscr...@googlegroups.com, PyScripter
Hello,

Done it.

Best regards,

JM
Reply all
Reply to author
Forward
0 new messages